Full Version: Export Query With Form Parameters To .csv File
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
skwilliams
I'm not sure if this is the right forum to post this question but.

I have a table with particular data that I want to export to a comma delimited file. The parameter values may vary daily.

I have a query which utilizes parameters from a form tied to a table so the parameters are stored. I'm viewing the query from within this form as a subform and it's working great.

Now the problem. I want to take these query results and export to a .csv file. I've tried this code
CODE
Private Sub btnProcessSamples_Click()
DoCmd.TransferText acExportDelim, , "qrySampleExport2", "G:\PODRiso\Sample Lists\Samples\Samples.csv", False
End Sub

, but it asks for the parameters already provided by the form. If I replace the query name with the name of the subform, I get this error.
Run-time error '3011'
The Microsoft Access database engine could not find the object 'subfrmSampleExport2'. Make sure the object exists and that you spell its name and the path name correctly.

Any ideas??
LionelRoodyn
Try this.
Make the parameter query a make table query and then run your export from the created table. Then you wont need any parameters in the query you are using for the export to csv.
vtd
QUOTE (LionelRoodyn @ Jun 24 2011, 06:20 AM) *
Make the parameter query a make table query and then run your export from the created table. Then you wont need any parameters in the query you are using for the export to csv.

Sorry but the method sounds like a lot of work that results in storing duplicate data which bloats the database file requiring cleaning up afterwards to me?

I am sure there are easier ways...

vtd
1. Please post details of the Form, SubForm and Controls relevant to the Query and most important, the name of the SubFormControl that houses the "SubForm" [subfrmSampleExport2]. Please note that the name of the SubFormControl may be different from the name of the Form being used as the "Subform".

2. Please post the SQL String of the Query [qrySampleExport2]

skwilliams
To make it easier to understand, I've created an Access database with all the relevant tables, queries and forms.

The table "tblMain" will accumulate new data daily. I will be changing the parameters for the needed export data periodically.

Currently, I'm only working with the tblMain (Samples) not the Catalog data in case you are wondering about the additional parameters on the form.

I hope this helps.

Thanks.
skwilliams
I figured it out. I just added [Forms]![frmCatSamProcessing]! to the switch in the query.

Thanks to everyone for their assistance.
vtd
Incorrect reference to the Form Control in the Query was what I suspected and therefore I asked for the SQL String of the Query and details of the Form.

Glad you worked it out...

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.