Solved

Access Export multiple queries to same Excel Spreadsheet

Posted on 2015-02-06
9
2,325 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
9 Comments
 
LVL 29

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 49

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-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 29

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 84
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 47

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
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…

776 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