Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

export to one txt from various tables 1

Status
Not open for further replies.

dossev

Technical User
Aug 19, 2003
1
BG
Hi,

Here is my problem. I want to export data from several tables to a txt file. Every row can have different number of columns.

For example:

Row1 Name(20 characters) Sirname(15 charactes) Age(2 characters)
Row2 CompanyName(10charecters) Address(10charecters)

with export specification I can set just one row and all following will be the same.

I want to write each line directly to the txt file specifying the export specification to be used.

10x in advance
 
could you create a master table that has all possible field names?

then run an append query procedure that appends all table data to the master table one table at a time.

then export the master table to your text file.
 
Dossev,

Not exactly an anwser to your question but i use below code for something fairly similar. Maybe it helps you.
It creates a tab delimited file in the directory the Db is running in.

Code:
Public Sub CreateCsv()

Dim dbCurrent As Database
Dim strFileName, strDbName As String
Dim rsTable As Object
Dim fsFile, tsFile As Object

    Set dbCurrent = CurrentDb
    Set fsFile = CreateObject("Scripting.FileSystemObject")
    strDbName = dbCurrent.Name
    strFileName = Mid(strDbName, 1, Len(strDbName) - Len(Dir(strDbName))) & "text.csv"
    Set tsFile = fsFile.CreateTextFile(strFileName, True)
    tsFile.WriteLine ("Name" & Chr(9) & _
                        "Sirname" & Chr(9) & _
                        "Age" & Chr(9) & _
                        "Companyname")
    Set rsTable = dbCurrent.OpenRecordset("Table")
    With rsTable
        .MoveFirst
        Do While Not .EOF
            tsFile.WriteLine (!Name & Chr(9) & _
                              !Sirname & Chr(9) & _
                              !Age & Chr(9) & _
                              !Companyname)
            .MoveNext
        Loop
        .Close
    End With
    tsFile.Close
    fsFile.Close
End Sub

"In three words I can sum up everything I've learned about life: it goes on."
- Robert Frost 1874-1963
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top