Access Queries to the same excel spread sheet

Dear Experts

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

I am using the following codes

'------------------------------------------------------------
' ExportToExcel
'
'------------------------------------------------------------
Function ExportToExcel()
On Error GoTo ExportToExcel_Err

    DoCmd.OutputTo acOutputQuery, "TRERequired_Summary", "Excel97-Excel2003Workbook(*.xls)", "C:\Users\OWNER\Desktop\Test\TRERequired_Summary.xls", False, "", , acExportQualityScreen
    DoCmd.OutputTo acOutputQuery, "TRERequired", "Excel97-Excel2003Workbook(*.xls)", "C:\Users\OWNER\Desktop\Test\TRERequired_Summary.xls", False, "", , acExportQualityScreen


ExportToExcel_Exit:
    Exit Function

ExportToExcel_Err:
    MsgBox Error$
    Resume ExportToExcel_Exit

End Function


Many thanks
LVL 1
Vinod GodghateAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rgonzo1971Commented:
Hi,

pls try
Function ExportToExcel()
 On Error GoTo ExportToExcel_Err
     DoCmd.TransferSpreadsheet acExport, AcSpreadsheetTypeExcel9, "TRERequired_Summary", "C:\Users\OWNER\Desktop\Test\TRERequired_Summary.xls", , "Sheet1"
     DoCmd.TransferSpreadsheet acExport, AcSpreadsheetTypeExcel9, "TRERequired", "C:\Users\OWNER\Desktop\Test\TRERequired_Summary.xls", , "Sheet2"
     
ExportToExcel_Exit:
     Exit Function

ExportToExcel_Err:
     MsgBox Error$
     Resume ExportToExcel_Exit

 End Function

Open in new window

Regards
0
Vinod GodghateAuthor Commented:
Thanks for the prompt comment

But if I run the command .......

Function ExportToExcel()
 On Error GoTo ExportToExcel_Err
     DoCmd.TransferSpreadsheet acExport, AcSpreadsheetTypeExcel9, "TRERequired_Summary", "C:\Users\OWNER\Desktop\Test\TRERequired_Summary.xls", , "Sheet1"
     DoCmd.TransferSpreadsheet acExport, AcSpreadsheetTypeExcel9, "TRERequired", "C:\Users\OWNER\Desktop\Test\TRERequired_Summary.xls", , "Sheet2"
     
ExportToExcel_Exit:
     Exit Function

ExportToExcel_Err:
     MsgBox Error$
     Resume ExportToExcel_Exit

 End Function


The Commad window for MACRO get opened.
the excel file is not created .

Thanks
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Rgonzo1971Commented:
which message error?
0
Vinod GodghateAuthor Commented:
Thanks for the response . I used the following code IT WORKED . NOW IT IS FINE


'------------------------------------------------------------
' ExportToExcel
'
'------------------------------------------------------------
Function ExportToExcel()
On Error GoTo ExportToExcel_Err

    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "TRERequired_Summary", "C:\Users\OWNER\Desktop\Test\TRERequired_Summary.xls", True
    DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "TRERequired", "C:\Users\OWNER\Desktop\Test\TRERequired_Summary.xls", True
   

thanks
ExportToExcel_Exit:
    Exit Function

ExportToExcel_Err:
    MsgBox Error$
    Resume ExportToExcel_Exit

End Function
0
Rgonzo1971Commented:
A solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.