Export 'csv' using Access2007

O

OldManEd

How does one export a 'csv' (or txt) from a Access 2007 query?

I want the format to look something like:

"First","Last","email"<CR><LF>

ed
 
A

Arvin Meyer [MVP]

You can use I/O code:

Dim db as DAO.Database
Dim rst as DAO.Recordset

Set db = CurrentDb
Set rst = db.Openrecordset("YourQuery")

Open "C:\DatabaseFolder\YourFile.csv" For Output As #1
'Add any header information that you want

rst.MoveFirst

Do Until rst.EOF
'Copy in the record information something like
Print #1, rst!First; & "," rst!Last; & "," & rst!email & vbCrLf
rst.MoveNext
Loop

Close #1

rst.Close
Set rst = Nothing
Set db = Nothing

or you can use the TransferText Method:

DoCmd.TransferText acExportDelim, , "YourQuery",
"C:\DatabaseFolder\YourFile.csv"

Using this method, the query can contain only the 3 fields you want to
export.
 
O

OldManEd

Thanks for the VBA code. I recall I had no problem doing this directly with
Access 2003. Just another reason why I am so sorry I ever upgraded to 2007.
Ed
 

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