By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,705 Members | 1,891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,705 IT Pros & Developers. It's quick & easy.

DoCmd.OutputTo acOuputQuery -- Eats Query! Where did all my SQL go?

P: n/a
This code is behind a button that exports the contents of a query
("qryXL_Tx") to an Excel spreadsheet. It works fine the first time, but
will not run a second time. When I go to look at my query... it's blank!
No SQL at all....

Any ideas why this sub is eating my query??

Private Sub cmdExportXL_Click()
strXLfile = "Transactions_" & strTxType & strTxAcct & strQtr & strYr &
".xls"
DoCmd.OutputTo acOutputQuery, "qryXL_Tx", acFormatXLS, strXLfile, False
MsgBox "Excel file saved as:" & Chr(13) & Chr(10) & Chr(13) & Chr(10) &
strXLfile, vbInformation, " Export To Excel Complete"
End Sub

many thanks...
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
I think the problem occurs only when the query does not return any records.
The following code appears to be an effective remedy, but still testing...

If DCount("Entity_ID", "qryXL_Tx") = 0 Then Exit Sub

"deko" <dj****@hotmail.com> wrote in message
news:no********************@newssvr21.news.prodigy .com...
This code is behind a button that exports the contents of a query
("qryXL_Tx") to an Excel spreadsheet. It works fine the first time, but
will not run a second time. When I go to look at my query... it's blank!
No SQL at all....

Any ideas why this sub is eating my query??

Private Sub cmdExportXL_Click()
strXLfile = "Transactions_" & strTxType & strTxAcct & strQtr & strYr &
".xls"
DoCmd.OutputTo acOutputQuery, "qryXL_Tx", acFormatXLS, strXLfile, False
MsgBox "Excel file saved as:" & Chr(13) & Chr(10) & Chr(13) & Chr(10) &
strXLfile, vbInformation, " Export To Excel Complete"
End Sub

many thanks...

Nov 12 '05 #2

P: n/a
The problem persisted, so I resorted to a make table query:

DoCmd.SetWarnings False
DoCmd.OpenQuery "qryXL_Tx" '<=== make table query
DoCmd.SetWarnings True
If DCount("Entity_ID", "tblXL_Tx") = 0 Then Exit Sub
DoCmd.OutputTo acOutputTable, "tblXL_Tx", acFormatXLS, strXLfile

"deko" <dj****@hotmail.com> wrote in message
news:L7*****************@newssvr27.news.prodigy.co m...
I think the problem occurs only when the query does not return any records. The following code appears to be an effective remedy, but still testing...

If DCount("Entity_ID", "qryXL_Tx") = 0 Then Exit Sub

"deko" <dj****@hotmail.com> wrote in message
news:no********************@newssvr21.news.prodigy .com...
This code is behind a button that exports the contents of a query
("qryXL_Tx") to an Excel spreadsheet. It works fine the first time, but
will not run a second time. When I go to look at my query... it's blank! No SQL at all....

Any ideas why this sub is eating my query??

Private Sub cmdExportXL_Click()
strXLfile = "Transactions_" & strTxType & strTxAcct & strQtr & strYr &
".xls"
DoCmd.OutputTo acOutputQuery, "qryXL_Tx", acFormatXLS, strXLfile, False
MsgBox "Excel file saved as:" & Chr(13) & Chr(10) & Chr(13) & Chr(10) &
strXLfile, vbInformation, " Export To Excel Complete"
End Sub

many thanks...


Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.