Access:- Execute Queries and export in single file

sanket_sk

Board Regular
Joined
Dec 27, 2016
Messages
140
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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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.
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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
Back
Top