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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I wirte some code to save table as a .csv file 1

Status
Not open for further replies.

JONBOY74

Technical User
Sep 11, 2001
36
0
0
US
Hi all

I would like to write some code that would to the same job as SaveAs\Export. I want to be able to save a tables contents as a .csv file.

Can anyonr help me?

Thanks

Jon
 
Hi Jon

The DoCmd transferText method passing the acExportDelim parametr will create a comma seperated file but the extension unless specified will be .txt so if you want to have the .csv extension make sure to specify it in your file name parameter. An example I used is:

DoCmd.TransferText acExportDelim, , QueryName, FileName, False

Hope this helps,
Rewdee
 
Redee (or anyone who can help)

Thanks for the info it's worked a treat, one thing though I've got "" marks around the text data in the .txt file.

Is there a way of removing them before the file is created

Thanks

Jon
 
Hi!

I am not sure if you can do it in code or not, but if you go through the Save as (Export in A2k) then you will be able click on the advanced button and you can choose to have no text qualifiers. Then you will click on specs and save the specifications. After that you can set up a macro to transfer text using the specification file to determine how the transfer takes place. Finally, in code, you can run the macro.

hth
Jeff Bridgham
 
You can then use the Specification in your transfer command as follows:

DoCmd.TransferText acExportDelim,&quot;<specification name>&quot; , QueryName, FileName, False

No need to use a macro command.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top