I didn't ask the question correctly. (Sorry, I have a bad habit
of using terms implicitly.)
What I want to do is write a message and exit a report when
the RecordSource is found to be empty at open time. By that
I mean the query specified by the RecordSource returns an
empty recordset. I.e., there are no records for the report to
process.
I put your suggested code in the OnOpen code but it
didn't seem to catch the empty recordset.
Your original post was confusing as to what you meant.
A better way to ask your question would be
'How do I handle a report that has no data?'
Use the Report's OnNoData event:
MsgBox "there were no records to show in this report."
Cancel = True
If you have opened this report from the command button on a form,
this will result in Error 2501, so just trap it in the command button's
error handler:
On Error GoTo Err_Handler
DoCmd.OpenReport "ReportName", acViewPreview
Exit_This_Sub:
Exit Sub
Err_Handler:
If Err = 2501 then
Else
MsgBox "Error #: " & Err.Number
End If
Resume Exit_This_Sub
Thanks Fred, your suggestion worked perfectly.
The confusion on my part arose from some preconceived
ideas on how the testing might work and so I formulated
the question accordingly... wrong as you've already observed.
Thanks again,
Bill
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.