B
B F Cole
I have several tables that I want to export to Excel and have them exist on
separate worksheets within the same workbook. I'm using this code which
creates the Excel workbook. How do I cause the second output query to
create the second sheet in the same Workbook. instead of overwriting
theWorkbook and having only the last output as a worksheet?
sExcelFile = "DataTables.xls"
stDocName = "qryTable1"
' First Table to output
On Error Resume Next
DoCmd.OutputTo acOutPutQuery, stDocName, acFormatXLS, sExcelFile, 0
If Err Then
iAnswer = MsgBox("Error detected on Output 1",vbCritical)
End If
' Second Table to output
stDocName = "qryTable2"
On Error Resume Next
DoCmd.OutputTo acOutPutQuery, stDocName, acFormatXLS, sExcelFile, 0
If Err Then
iAnswer = MsgBox("Error detected on Output 2",vbCritical)
End If
etc, for more tables
Thanks for your suggestions. They have always solved a problem quickly.
Bill
separate worksheets within the same workbook. I'm using this code which
creates the Excel workbook. How do I cause the second output query to
create the second sheet in the same Workbook. instead of overwriting
theWorkbook and having only the last output as a worksheet?
sExcelFile = "DataTables.xls"
stDocName = "qryTable1"
' First Table to output
On Error Resume Next
DoCmd.OutputTo acOutPutQuery, stDocName, acFormatXLS, sExcelFile, 0
If Err Then
iAnswer = MsgBox("Error detected on Output 1",vbCritical)
End If
' Second Table to output
stDocName = "qryTable2"
On Error Resume Next
DoCmd.OutputTo acOutPutQuery, stDocName, acFormatXLS, sExcelFile, 0
If Err Then
iAnswer = MsgBox("Error detected on Output 2",vbCritical)
End If
etc, for more tables
Thanks for your suggestions. They have always solved a problem quickly.
Bill