Link to home
Start Free TrialLog in
Avatar of Kiekeboe
KiekeboeFlag for Netherlands

asked on

VBA Export Table to CSV file

Hi

I want to make a "export"button on a form to transform a table into a .csv file.
Can somebody help me with the right VBA code?

I've tried things like:
DoCmd.TransferSpreadsheet acExport, "RESULTS", "C:\Temp\Results.csv"

Hopefully somebody can help me

J
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image


'--------------------------------------------vvvvvvvvvvvvvvvvvvvvvvvv- you are just missing the version of excel
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "RESULTS", "C:\Temp\Results.csv"
Avatar of RohitPattni
RohitPattni

Hi

You are trying to create a csv file so I would use
DoCmd.TransferText acExportDelim, "specificationname", "tablename", "file name", False, "headersrequired"

Use the specifation name to create the template for the ouput eg date formats, quotes to wrap around text etc

You can as easily create the out froma macro  where the action is "TransferText" and then fill in the boxes below.

Rohit
or

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "RESULTS", "C:\Temp\Results.csv", True
Hi, take a look at the help file for the 'OutputTo' Method

DoCmd.OutputTo ...

You may have to run the install for access in order to add filters for CSV file format support.

Good Luck

Toby
Kiekeboe,
ignore my post, did not see that it is a csv file. my post is only good for .xls files
Avatar of Kiekeboe

ASKER

Thanks for your reactions. The export to an Excel file works fine, but csv not yet.
Any tips?
HI did you try the the transfertext command i suggested. That should produce the csv file you require. Don't forget to set the export specification. This is easily done when you do a export file and then click on the advanced button check the setting and the save the specification.

Rohit
@Rohot

I've tried it, but i don't understand what to do with "specificationname" and "headersrequired".


DoCmd.TransferText acExportDelim, "specificationname", "RESULTS", "C:\TEMP\results.csv", False, "headersrequired"
 
ASKER CERTIFIED SOLUTION
Avatar of RohitPattni
RohitPattni

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Rohit, that's it!