Solved

Access Export multiple queries to same Excel Spreadsheet

Posted on 2015-02-06
9
2,016 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
 
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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 
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 119

Accepted Solution

by:
Rey Obrero 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
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…

920 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now