Solved

Access Export multiple queries to same Excel Spreadsheet

Posted on 2015-02-06
9
3,532 Views
Last Modified: 2016-02-10
Dear Experts

I'm not sure if this is even possible - I want to export 2 Access Queries to the same excel spread sheet so query 1 goes to sheet 1 & query 2 goes to sheet 2.  I am using Access & Excel 2010

For various reasons this has to be an export rather than simply linking the excel spread sheet back to Access.

Can anybody help with some code to achieve this

Many thanks
0
Comment
Question by:correlate
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 30

Expert Comment

by:gowflow
ID: 40593197
Not too much into Access but your doing this viaa VBA in Access or from the menu manually ?
gowflow
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 40593236
Hi,

pls try

 DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "myQry1", "c:\myFile.xlsx", True, , "Sheet1!A1:C1"

Regards
0
 

Author Comment

by:correlate
ID: 40593283
Hi, thanks for the rapid response ..

gowflow - I'm looking at using VBA, triggered from a command button in a form

Rgonzo1971 - I have tried your code, alas I get an error - 2498 "An expression you entered is the wrong data type for one of the arguments - the code I've entered is below - Any Ideas?

Private Sub ExportAnalysis_Click()
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Analysis-Cost", "C:\Users\xxxxx\Google Drive\Accounts\Analysis.xlsx", True, , "Sheet1!A1:E1"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "Analysis-Turnover", "C:\Users\xxxxx\Google Drive\Accounts\Analysis.xlsx", True, , "Sheet2!A1:E1"
End Sub

Open in new window

0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 30

Expert Comment

by:gowflow
ID: 40593296
Just omit
acSpreadsheetTypeExcel12Xml

try
Private Sub ExportAnalysis_Click()
DoCmd.TransferSpreadsheet acExport, , "Analysis-Cost", "C:\Users\xxxxx\Google Drive\Accounts\Analysis.xlsx", True, , "Sheet1!A1:E1"
DoCmd.TransferSpreadsheet acExport, , "Analysis-Turnover", "C:\Users\xxxxx\Google Drive\Accounts\Analysis.xlsx", True, , "Sheet2!A1:E1"
End Sub

Open in new window


gowflow
0
 
LVL 85
ID: 40593318
You can't use a Range value when exporting:

Leave this argument blank to import the entire spreadsheet. When you export to a spreadsheet, you must leave this argument blank. If you enter a range, the export will fail.
From here: https://msdn.microsoft.com/en-us/library/office/ff844793.aspx

Only way I know to do this is through automation.
0
 

Author Comment

by:correlate
ID: 40593322
Hi

Thanks for that - gave it a go, but got the same error message I'm afraid
0
 
LVL 48

Expert Comment

by:Dale Fye (Access MVP)
ID: 40593384
Check out this response to a previous question for instructions on how to use automation and the CopyFromRecordset method to export Access data to a specific location in your workbook.
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 40593424
try this copy and paste

Private Sub ExportAnalysis_Click()
DoCmd.TransferSpreadsheet acExport, 10, "Analysis-Cost", "C:\Users\xxxxx\Google Drive\Accounts\Analysis.xlsx", True, "Sheet1"
DoCmd.TransferSpreadsheet acExport, 10, "Analysis-Turnover", "C:\Users\xxxxx\Google Drive\Accounts\Analysis.xlsx", True,"Sheet2"
End Sub
0
 

Author Closing Comment

by:correlate
ID: 40593433
Brilliant, works a treat - thank you very much
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question