Access:- Execute Queries and export in single file

sanket_sk

Board Regular
Joined
Dec 27, 2016
Messages
67
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have small doubt in Access data base.

I have database in which I have setup 4 different queries.

I want functionality by which I can execute / refresh these queries and export all queries in single excel sheet.

Could you please help me performing this activity.

Sanket
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

ranman256

Well-known Member
Joined
Jun 17, 2014
Messages
1,993
the last param is the tab name if you want different tabs:
Code:
vFile = "C:\mypath\files\" & format(date(),"yyyy-mm-dd" & "_ExportFile.xlsx"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "query1", vFile, True,"qry1"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "query2", vFile, True, "qry2"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "query3", vFile, True, "qry3"

if you want ALL queries in 1 tab, then make a UNION query to put them all in 1 query, qnUnion:
select * from query1
union
select * from query2
union
select * from query3

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qnUnion", True,"unionqry"
BUT EVERY QUERY MUST HAVE THE EXACT SAME #FIELDS AND FIELD ORDER.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,573
Messages
5,659,603
Members
418,513
Latest member
TWEagle

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top