Empty report

  • Thread starter Thread starter Hanksor
  • Start date Start date
H

Hanksor

Is there a way to have an alert pop up if a report that is opened is
empty(Null)? Any help is appreciated.....
 
Hanksor said:
Is there a way to have an alert pop up if a report that is opened is
empty(Null)? Any help is appreciated.....

Use the OnNoData event of the report.

MsgBox "No data"


You can optionally include another line of code to cancel the opening of the
form...

MsgBox "No data"
Cancel = True

....however if the report is being opened via code (like from a button press)
then that calling code will interpret the cancel as an error. The number of
that error (2501) will need to be trapped for and ignored.
 
Hanksor said:
Thanks Rick,

I'm not that familiar with trapping errors. Any quick suggestions?

Assuming you have a button that opens the report...

Private Sub MyButton_Click()

On Error GoTo ErrHandler

DoCmd.OpenReport "ReportName", acViewPreview

Egress:
Exit Sub

ErrHandler:
If Err.Number = 2501 Then
'ignore
Else
MsgBox Err.Description
End If
Resume Egress
End Sub
 
Back
Top