Full Version: Exporting Quires
UtterAccess Discussion Forums > Microsoft® Access > Access Queries
zepp27
Is there a way to export multiple saved quires as a .txt file at one time? I always have to do them one by one and I am looking for a faster way. Thanks.
RAZMaddaz
Well, if ALL the Queries have the same fields, then you could create a Union query to combine all the queries and then Export the Union query. Sound good?

RAZ
markv
You might want to look at viewing the queries in documenter and exporting them from there. Go to Tools---Analyze---Documenter. Select the queries that you want. Select OK. Go to File ---- Export.
zepp27
I cannot combine the queries because they have to be separate do to the selected criteria in them. They do however have the same fields just different data. All the queries must be exported as a .txt file. This may not be possible but I though I would ask. Thanks for all the responses so far. I really hope there is a way to do this.
markv
Documenter does that. Do you need a single file for each query?
zepp27
Yes.
HiTechCoach
Pardon me for jumping in here ....

I use VBA code to do this. I have found that it works better to first run a make table query using your saved query as the source and storing the data into a temp table. Then you can export the table.

You may be able to export from your saved queries directly.

CODE


' run the make table queries

  CurrentDB.Execute "qryExport_1_MakeTable"

  CurrentDB.Execute "qryExport_2_MakeTable"

  CurrentDB.Execute "qryExport_3_MakeTable"

  CurrentDB.Execute "qryExport_4_MakeTable"



' export the data from the tables



  DoCmd.TransferText acExportDelim, , "tmpExportTable1", strPath & "\qryExportTable1.txt", True

  DoCmd.TransferText acExportDelim, , "tmpExportTable2", strPath & "\qryExportTable2.txt", True

  DoCmd.TransferText acExportDelim, , "tmpExportTable3", strPath & "\qryExportTable3.txt", True

  DoCmd.TransferText acExportDelim, , "tmpExportTable4", strPath & "\qryExportTable4.txt", True






zepp27
I have never really used VBA codes is there any way you could walk me through this? Do I use the exact code you wrote out below to export the queries? Do I have to make the queries into tables in order for the VBA code to work? Where do I insert the VBA code? Sorry for so many questions I am new to some of this stuff in Access. Thanks for all the help.
HiTechCoach
You could place this code in the On Click event of a Command Button on a form.

The DoCmd.TransferText is designed to export or import the contents of a table. See the help file for a complete description of what it does.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.