Exporting query results to an external CSV file.

T

Travis

I have a little C# program which was written for me by a friend which
takes a list of stock codes in a file called stockcodes.csv and looks
up their prices and some other data from a web site and outputs the
data to a new file called output.csv

Now that I've (partially) built an Access application which has details
of which stocks are owned by a group of people, I want to export the
results of a query which returns a list of all the stocks owned by a
client into my file stockcodes.csv. I then run the web update program,
then I want to import the data from output.csv back into my Access
application.

The query isn't a problem, its easy enough to produce a list of stock
codes owned by an investor.

What I want to know is how to get my query (of the stock codes) into
the stockcodes.csv file. I'll then manually run the downloader and
when its finished I want to import the data into my database using
update queries to amend the data in my database.

So how do I get query output into, and then out of, .csv files?

Travis
 
A

Allen Browne

The TransferText action (in a macro) or method (in VBA code) can export and
import delimited text.
 
T

Travis

Allen said:
The TransferText action (in a macro) or method (in VBA code) can export and
import delimited text.

Thanks Allen.

Google wasn't much help until I knew exactly what to search for. A bit
of scratching around with do.Cmd.TransferText and I've found mention
of:

DoCmd.TransferText acImportDelim, "ImportSpec", "TableName",
"path\importfile.csv", Hasfieldnames:=True ,""

Where "Importspec" is a saved specification which can be saved from the
advanced options when importing a .csv via the wizard. I assume this
spec is stored inside the Jet file?

And when exporting:

DoCmd.TransferText acExportDelim, "ExportSpec", "Query",
"path\exportfile.csv"

Where "Exportspec" is similarly saved via the advanced options of the
Export menu.

Is this right?

Travis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top