[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 15612
  • Last Modified:

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
0
Kiekeboe
Asked:
Kiekeboe
  • 3
  • 3
  • 3
  • +1
1 Solution
 
Rey Obrero (Capricorn1)Commented:

'--------------------------------------------vvvvvvvvvvvvvvvvvvvvvvvv- you are just missing the version of excel
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "RESULTS", "C:\Temp\Results.csv"
0
 
RohitPattniCommented:
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
0
 
Rey Obrero (Capricorn1)Commented:
or

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "RESULTS", "C:\Temp\Results.csv", True
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
daviesgroupCommented:
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
0
 
Rey Obrero (Capricorn1)Commented:
Kiekeboe,
ignore my post, did not see that it is a csv file. my post is only good for .xls files
0
 
KiekeboeAuthor Commented:
Thanks for your reactions. The export to an Excel file works fine, but csv not yet.
Any tips?
0
 
RohitPattniCommented:
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
0
 
KiekeboeAuthor Commented:
@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"
 
0
 
RohitPattniCommented:
Specification is how you tell access to export the text file, whether the delimiter is a comma (for Comma Seperated Values [CSV]) or tabs (Tab delimited) if left blank it will default to access which is comma on my machine
Headers required is whether the field names are required at the beginning of the file.

Try this simple statement:

DoCmd.TransferText acExportDelim, "", "RESULTS", "C:\TEMP\results.csv", False, "" 
0
 
KiekeboeAuthor Commented:
Thanks Rohit, that's it!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 3
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now