Question about DoCmd.TransferText

JC10001

Registered User.
Local time
Today, 19:03
Joined
Sep 24, 2003
Messages
48
Hello,

I am trying to export a table generated by a query. I am using the following line of code to output to a file.

DoCmd.TransferText acExportDelim, , MyTbl, "C:\whatever\" & ExportName & ".txt"

This will generate a comma delimited text file with the results. What I would like to do is on the first line specify the field names for the table. So if the field names were "Last Name", "First Name", "Telephone Number" then the text file would look like this:

Last Name, First Name, Telephone Number
"Anderson", "Carl" 222-2222
"Smith", "John", 555-5555
"Zane", "Max", 444-4444

How would I go about doing this? I've tried looking stuff up on the web but I can't seem to find anything.
 
Add True at the end for HasFieldNames:-

DoCmd.TransferText acExportDelim, , MyTbl, "C:\whatever\" & ExportName & ".txt", True
 
Include field names

Including the last two parameters allows you to say to include field names in the export (true) so provided your access table fields are correctly named (you could change these as part of your query, if needs be), you can use the following:

DoCmd.TransferText acExportDelim, , MyTbl, "C:\whatever\" & ExportName & ".txt",True,""

HTH
 
Awesome. Thanks for the help guys and for the quick response.
 
Tim L said:
How does this work?

In on e of the empty field boxes:

NewFieldName: [MyField]


So,


DOB: [DateOfBirth]



a field called DateOfBirth in a table can be changed (for the query) to DOB.
 
Ah, so that's it.

Thanks Mile-O-Phile.

Tim
 
Including the last two parameters allows you to say to include field names in the export
The final "" is unnecessary for acExportDelim.

Quoted from the Access help file:-
HTMLtablename     A string expression that's the name of the table or list in the HTML file that you want to import or link. This argument is ignored unless the transfertype argument is set to acImportHTML or acLinkHTML. If you leave this argument blank, the first table or list in the HTML file is imported or linked.
 
EMP

Thanks for clarifying my post.
Cheers.
 

Users who are viewing this thread

Back
Top Bottom