473,320 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Save a query as .csv

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
3 7047
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Adrian Parker | last post by:
Hi. I would like to query a database, given several where clauses to refine my search, and return the value of one single field in the database. eg: I have a table that lists teachers. Their...
1
by: Eric Nelson | last post by:
Here's what happens. I created the query below in a copy of my BE & it works fine. But in the FE: If I enter query into SQL view & hit "!" I get correct results (a list of families...
5
by: Carl | last post by:
Please can anyone tell me how I can create a macro to save the results of a query as an excel file? The query is called Student List and I would like to save it to "My Documents". We have had...
5
by: Norma | last post by:
I am trying to make a query pull data from between the dates I enter in the parameter but also look back 'in time' to see where 2 other fields have null values, and only pull data into the query if...
1
by: mansoorsheraz | last post by:
Hi there, I am, doing a project in which i need the user to have his account history downloaded. I am, doing this project in PHP and mysql. There is a link on the account history page...
3
by: Alex Resnik | last post by:
Hi, When I build a new query the program will not let me save it -the save button is not selectable. This happens when I click on my table in Server Exporer. Click New Query and the Query Window...
1
by: eighthman11 | last post by:
Hello everyone. I have a table linked to an excel spreadsheet. I have an append query based on this link table. I receive an error when I run the append query "numeric field overflow". I have...
2
by: nuhura01 | last post by:
Hi.. I'm trying to save query path which is in text box to text file. Below is the coding that i'm using currently: Private Sub SaveQueryPath() 'save to text file Response.Clear()...
3
xxoulmate
by: xxoulmate | last post by:
saving query results to a file select * from table into outfile savepath is it possible to save the query result directly to blob field in a table e.g. something like below insert into...
0
by: tetsuo2030 | last post by:
Greetings all, Can't figure this out. I have a table with three fields: , , . I want to show this data as a pivot table with Users on the Y-Axis, Months on the X-axis, and TextValues in the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.