In
D Rius said:
Thank you so much for your help. When you are referring to saving
each query as a separate sheet in an Excel Workbook would this have
to be done manually or can it be done programmatically?
Sure, it can be done programmatically with ease. You use the
DoCmd.TransferSpreadsheet method. To export two queries to separate
sheets in the same workbook, you would use code similar to this:
'----- start of example code -----
Dim strOutputFile As String
strOutputFile = "C:\Temp\MyExcelFile.xls"
DoCmd.TransferSpreadsheet _
acExport, _
acSpreadsheetTypeExcel9, _
"Query1", _
strOutputFile, _
True
DoCmd.TransferSpreadsheet _
acExport, _
acSpreadsheetTypeExcel9, _
"Query2", _
strOutputFile, _
True
'----- end of example code -----
Since the code didn't specify the Range argument for
TransferSpreadsheet, that will create (or replace) worksheets named
"Query1" and "Query2" in the Excel workbook. The workbook itself will
be created if it doesn't already exist.
If you want, you can name the worksheets when you export the queries, as
in this example:
DoCmd.TransferSpreadsheet _
acExport, _
acSpreadsheetTypeExcel9, _
"Query1", _
strOutputFile, _
True, _
"Sales"
DoCmd.TransferSpreadsheet _
acExport, _
acSpreadsheetTypeExcel9, _
"Query2", _
strOutputFile, _
True, _
"Revenue"