Open a recordset over the query. Loop through the records, opening an output file for each one and Printing the fields from the record into the file, with separating commas.
Help topics you might need:
Database Object
OpenRecordset method
Close method
Recordset Object
EOF property
MoveNext method
FreeFile function
Open statement
Print statement
Close statement
Rick Sprague
Want the best answers? See faq181-2886 To write a program from scratch, first create the universe. - Paraphrased from Albert Einstein
If you're looking for a manual method, open query, chose from menu: File, Export. Choose Text Files as type, and give destination filename. Click Save, and Export Wizard begins (Access 2000). If you're looking for a more automated method to use in a macro, or VBA code (preferred), then look at the TransferText method. VBA basic command is:
You mean for instance, your query returns 100 records...You want to write a separate CSV file for each of the 100 records? What do you mean by "one file from the query?" Are you saying the CSV filename is part of the records returned? Just curious.
Well, it looks like your going to have to take Rick's advice above and do some coding. Using DAO, maybe code like:
Set DB = CurrentDB()
Set RS = DB.OpenRecordset("qryName"
Do until RS.EOF
Filename = RS![ExportFileName]
OutF = FreeFile
Open Filename For Output As OutF
Print #OutF, RS![Field1] & "," & RS[Field2] & ",' & Etc.
Close #OutF
RS.MoveNext
Loop
RS.Close
DB.Close
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.