Quick one

  • Thread starter Thread starter Bill Stanton
  • Start date Start date
B

Bill Stanton

If a report's RecordSource (query) is empty,
"where" (what event) and "how" does one test
for that?

Thanks,
Bill
 
You could use any event you wish. Simply this code step:

If Me.RecordSource = "" Then
' record source is "empty"
Else
' record source is not empty
End If
 
Hi Ken!

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.

Bill
 
Bill,

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
 
Back
Top