By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,061 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Save a query as .csv

P: n/a
I have a query q401k which has parameter [Start Date] and [End Date]. I
need the recordset of the query to be exported to a .csv file. Does
anyone know how to do this?

I am currently using a macro to automatically send it to Excel. In
Excel I have a macro that formats and saves it as a .csv file. The
user has to click a button in the Excel spreadsheet to run the macro.
I am trying to automate it so she doesn't have to anything but click a
cmd button in Access.

Thanks

Aug 24 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On the same form where you put this command button for your user, put a pair
of text boxes named (say) StartDate and EndDate. The user can enter the
dates there, and the query can read the dates from the form and perform the
export.

The Criteria in your query would change to:
Between [Forms].[Form1].[StartDate] And [Forms].[Form1].[EndDate]

Hint: Set the Format property of the text boxes to Short Date, so only valid
dates are accepted, and Access knows how to interpret them.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"newkid" <mt*******@yahoo.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>I have a query q401k which has parameter [Start Date] and [End Date]. I
need the recordset of the query to be exported to a .csv file. Does
anyone know how to do this?

I am currently using a macro to automatically send it to Excel. In
Excel I have a macro that formats and saves it as a .csv file. The
user has to click a button in the Excel spreadsheet to run the macro.
I am trying to automate it so she doesn't have to anything but click a
cmd button in Access.

Thanks

Aug 24 '06 #2

P: n/a
Hi,

You could create a form with 2 text boxes for your start date and end
date. Make your query a "make table" query so each time its run it
overwrites the new table, Then your command button could run the query
and export the resulting recordset.

So your query would have the parameters StartDate =
Forms!myParamForm.txtStartDate and EndDate =
Forms!myParamForm.txtEndDate.

Then the code behind the click event of your command button would be
something like:

FName = "C:\Somefolder\Somename.csv"
DoCmd.OpenQuery "qryMakeExportTable"
DoCmd.TransferText acExportDelim, "", "tblTableMadeByQuery", FName,
True, ""

hth

newkid wrote:
I have a query q401k which has parameter [Start Date] and [End Date]. I
need the recordset of the query to be exported to a .csv file. Does
anyone know how to do this?

I am currently using a macro to automatically send it to Excel. In
Excel I have a macro that formats and saves it as a .csv file. The
user has to click a button in the Excel spreadsheet to run the macro.
I am trying to automate it so she doesn't have to anything but click a
cmd button in Access.

Thanks
Aug 25 '06 #3

P: n/a
Hi,

You could create a form with 2 text boxes for your start date and end
date. Make your query a "make table" query so each time its run it
overwrites the new table, Then your command button could run the query
and export the resulting recordset.

So your query would have the parameters StartDate =
Forms!myParamForm.txtStartDate and EndDate =
Forms!myParamForm.txtEndDate.

Then the code behind the click event of your command button would be
something like:

FName = "C:\Somefolder\Somename.csv"
DoCmd.OpenQuery "qryMakeExportTable"
DoCmd.TransferText acExportDelim, "", "tblTableMadeByQuery", FName,
True, ""

hth

newkid wrote:
I have a query q401k which has parameter [Start Date] and [End Date]. I
need the recordset of the query to be exported to a .csv file. Does
anyone know how to do this?

I am currently using a macro to automatically send it to Excel. In
Excel I have a macro that formats and saves it as a .csv file. The
user has to click a button in the Excel spreadsheet to run the macro.
I am trying to automate it so she doesn't have to anything but click a
cmd button in Access.

Thanks
Aug 25 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.