Export to CSV File with table headers

tbasher

Registered User.
Local time
Today, 17:31
Joined
Jul 30, 2001
Messages
10
Currently I am using the following code to export to a .csv file, however, the table headers do not come across:
DoCmd.TransferText acExportDelim, , "QueryName", "test.csv"


I can use the following code to export into a .xls file and the table headers come across. The only problem is that I need a .csv and to do that I must open up excel then save as a .csv:
DoCmd.OutputTo acOutputTable, "queryname", acFormatXLS, "test.xls", 0

Is there any way to expot to a .csv file with the table headers?

Thanks!
 
Thanks Ken for the response. I tried the acFormattxt and it gave me a type mismatch error when I ran the command. Any more ideas?
 
The export wizard has has checkbox to 'Include field names on first row'.

Shouldn't this work?

ken
 
Sorry, You were trying to automate this...

Seems there is a 'HasFieldNames' switch in the trf text function...

???
ken
 
Use the folloing sentence:

DoCmd.TransferText acExportDelim, , "QueryName", "test.csv", True
 
just joined the forum and i was looking for a way to export a query to a csv file and this thread has been a great help!

the export goes to my Documents folder - which is not a train smash - but is there no way in specifying a specific file path instead.

for instance when creating a pdf of the report, the PDF file is saved in a corresponding month end folder within a designated client folder.

With the CSV going to the Documents folder, i will have to manually move to the client folder.
 
For some reason this isn't working for me, my code says:

Code:
DoCmd.TransferText acExportDelim, "MyTabDelimExport", "MyQueryName", "C:\MyFileName.TXT", True

And it exports without the headers

:confused:
 

Users who are viewing this thread

Back
Top Bottom