Export CSV to variable location

JoysTick

Registered User.
Local time
Today, 20:54
Joined
Sep 28, 2001
Messages
10
I've got a query I want to export [qryExport]. I want the user to be able to export the contents of the query to a CSV file to a location of their choice and for this to be run from a button on a form. Obviously I'm going to need to be able to specify save as CSV format in the underlying code, and be able to call a "standard" Save As type dialogue box to allow the choice of Save location (but not of file type as it must go to CSV).

How do I go about this? The MS Access Help on "Export File formats" seems to concentrate on doing this via the database window rather than coded buttons. I've had a quick search through this forum for some ideas but I can't find anything that really hits the spot. Any Routines or Code I should be looking at?

tx
 
I'd put a text box on the form where users can key in the location. I would do some editting in the after update of this field, so that you're sure it is reasonable. The user would not specify the file extension.

Then I'd have code like this on the export button. I am not familiar with .CSV formats, so I don't know if the acExportFixed
is right:

Dim strFileName as String
...
strFileName = Me.FileLoc & ".CSV"
Debug.Print strFileName 'for debugging

DoCmd.TransferText acExportFixed
, "", "qMyQuery", strFileName, False
 

Users who are viewing this thread

Back
Top Bottom