Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Apr 2007
    Posts
    22

    Question Unanswered: Trasfer all Database table to txt

    Dear,

    I have successful to transfer table to txt file, but now. I need transfer all table to txt,but without transfer one by one.It mean I need make the function that can transfer all table in one command.Example:

    I have databasename(SIA),Table(Employer,Material,Purchase ). In my case, I make all code in all form, but now I need to transfer without making every code in all form. This my code before:

    'For Function
    Function ExportTableToTxt(ByVal TableName As String, _
    ByVal FileName As String) As Boolean
    ExportTableToTxt = True
    DoCmd.TransferText acExportDelim, , TableName, FileName, True
    End Function

    'for Form Employer
    Private Sub Command13_Click()
    If ExportTableToTxt("Employer", "E:\DATABASE\SIA\Database\Employer.txt") Then
    MsgBox "Do You Want Export Data?", vbYesNoCancel, "Test Export Database"
    End If
    End Sub

    'For Form Material
    Private Sub Command13_Click()
    If ExportTableToTxt("Material", "E:\DATABASE\SIA\Database\Material.txt") Then
    MsgBox "Do You Want Export Data?", vbYesNoCancel, "Test Export Database"
    End If
    End Sub

    'For Form Purchase
    Private Sub Command10_Click()
    If ExportTableToTxt("Purchase", "E:\DATABASE\SIA\Database\Purchase.txt") Then
    MsgBox "Do You Want Export Data?", vbYesNoCancel, "Test Export Database"
    End If
    End Sub

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Here's some code that loops through all the forms in your application - very handy
    Code:
    Dim Frm As String
    
    For i = 0 To Application.CurrentDb.Containers("Forms").Documents.Count - 1
        Frm = Application.CurrentDb.Containers("Forms").Documents(i).Name
        Debug.Print Frm
    Next i
    George
    Home | Blog

  3. #3
    Join Date
    Apr 2007
    Posts
    22

    Question

    I try, but Item not found.And I need table not Form.

    this my script :
    For i = 0 To Application.CurrentDb.Containers("E:\DATABASE\SIA\ Database").Documents.Count - 1
    frm = Application.CurrentDb.Containers("E:\DATABASE\SIA\ Database").Documents(i).Name
    Debug.Print frm
    Next i

  4. #4
    Join Date
    Apr 2007
    Posts
    22
    Or I have script to, but this Only read 1 table and the filename didn't changed.

    Private Sub Label2_Click()
    Dim TblName As String

    Dim TblDef As dao.TableDef




    For Each TblDef In CurrentDb.TableDefs
    If Not Left(TblDef.Name, 4) = "MSys" Then
    TblName = TblDef.Name
    Dummy = ExportTableToTxt(TblName, "E:\DATABASE\CPET\Database\TblName.txt")
    End If
    Next TblDef

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Remember this little fella?
    Code:
    For i = 0 To Application.CurrentDb.Containers("Forms").Documents.Count - 1
    If you don't want "Forms" what do you think "Forms" needs changing to?
    Look in the help file for containers
    George
    Home | Blog

  6. #6
    Join Date
    Apr 2007
    Posts
    22
    I have blank??? What is mean? "Forms"

  7. #7
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Change "Forms" to read "Tables"
    Note that this returns all tables AND queries
    George
    Home | Blog

  8. #8
    Join Date
    Apr 2007
    Posts
    22
    Sorry I am stupid.Do nothing:

    For i = 0 To Application.CurrentDb.Containers("Tables").Documen ts.Count - 1
    Frm = Application.CurrentDb.Containers("Tables").Documen ts(i).Name
    Debug.Print Frm
    Next i

    I need to transfer to :
    ("Employer", "E:\DATABASE\SIA\Database\Employer.txt")
    ("Material", "E:\DATABASE\SIA\Database\Material.txt")
    ("Purchase", "E:\DATABASE\SIA\Database\Purchase.txt")

  9. #9
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    This is NOT the answer - rather a prod in the direction of the answer. Here's a more obvious way of showing you what it's doing.
    Code:
    Dim Frm As String
    Dim Msg As String
    
    Msg = ""
    
    For i = 0 To Application.CurrentDb.Containers("Forms").Documents.Count - 1
        Frm = Application.CurrentDb.Containers("Forms").Documents(i).Name
        Msg = Msg & Frm & chr(13)
    Next i
    
    MsgBox Msg
    George
    Home | Blog

  10. #10
    Join Date
    Apr 2007
    Posts
    22
    It is Run, But nothing Table in (E:\DATABASE\SIA\Database\)
    Private Sub Label18_Click()
    Dim Frm As String
    Dim Msg As String

    Msg = ""

    For i = 0 To Application.CurrentDb.Containers("Tables").Documen ts.Count - 1
    Frm = Application.CurrentDb.Containers("Tables").Documen ts(i).Name
    Msg = Msg & Frm & Chr(13)
    Next i

    MsgBox Msg

  11. #11
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    So what was the result?
    What did you see?
    What does the above loop do?
    George
    Home | Blog

  12. #12
    Join Date
    Apr 2007
    Posts
    22
    My question is Where the table export location?

  13. #13
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    I repeat my questions from post #11
    Quote Originally Posted by georgev
    So what was the result?
    What did you see?
    What does the above loop do?
    Answer these before we go any further
    George
    Home | Blog

  14. #14
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Hi cevin

    You need to read & make an attempt to understand George's code. What you are getting here is guidance, support and a bit of education rather than a ready made answer on a plate
    Last edited by pootle flump; 05-04-07 at 07:50.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  15. #15
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Thank you Poots
    George
    Home | Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •