Access:- Execute Queries and export in single file

sanket_sk

Board Regular
Joined
Dec 27, 2016
Messages
51
Office Version
365
Platform
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
 

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

ranman256

Well-known Member
Joined
Jun 17, 2014
Messages
1,900
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.
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,264
Messages
5,510,191
Members
408,779
Latest member
Lermiapolar

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top