Connecting Tech Pros Worldwide Forums | Help | Site Map

Save a query as .csv

newkid
Guest
 
Posts: n/a
#1: Aug 24 '06
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


Allen Browne
Guest
 
Posts: n/a
#2: Aug 24 '06

re: Save a query as .csv


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" <mtrina_83@yahoo.comwrote in message
news:1156431272.479613.316890@i42g2000cwa.googlegr oups.com...
Quote:
>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

pmc1
Guest
 
Posts: n/a
#3: Aug 25 '06

re: Save a query as .csv


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:
Quote:
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
pmc1
Guest
 
Posts: n/a
#4: Aug 25 '06

re: Save a query as .csv


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:
Quote:
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
Closed Thread