Export to CSV File with table headers (1 Viewer)

tbasher

Registered User.
Local time
Today, 08:44
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!
 

tbasher

Registered User.
Local time
Today, 08:44
Joined
Jul 30, 2001
Messages
10
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?
 

KenHigg

Registered User
Local time
Today, 03:44
Joined
Jun 9, 2004
Messages
13,327
The export wizard has has checkbox to 'Include field names on first row'.

Shouldn't this work?

ken
 

KenHigg

Registered User
Local time
Today, 03:44
Joined
Jun 9, 2004
Messages
13,327
Sorry, You were trying to automate this...

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

???
ken
 

benti

New member
Local time
Today, 09:44
Joined
Aug 11, 2004
Messages
8
Use the folloing sentence:

DoCmd.TransferText acExportDelim, , "QueryName", "test.csv", True
 

tbasher

Registered User.
Local time
Today, 08:44
Joined
Jul 30, 2001
Messages
10
Adding 'True' worked. Thanks for the Help!
 

colonel66

New member
Local time
Today, 10:44
Joined
Jun 14, 2012
Messages
4
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.
 

battles

New member
Local time
Today, 03:44
Joined
Apr 21, 2014
Messages
3
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

Top Bottom