How cancel a report when error?

  • Thread starter Thread starter Rolf Rosenquist
  • Start date Start date
R

Rolf Rosenquist

I have a main form for Orders, and a sub form for OrderSpecification. In the
main form there is a button to preview the complete order. When there are
records in the subform and the user clicks the button, the report shows up
as intended. But if he clicks it and there are no records in the subform, an
error is shown and the code window is opened. That I have corrected with my
own message, saying that there are no records and then gone Exit Sub in the
Detail_Format sub in the report. But I cannot supress the report itself. It
shows up with #Error in the textbox.

How is it possible to skip the report when there are no records?
/ Rolf
 
Add code to the On No Data event property.

Private Sub Report_NoData(Cancel As Integer)
MsgBox "No records to report", _
vbOKOnly + vbInformation, _
"No Matching Records"
Cancel = True
End Sub
You may also need to trap for err.number 2501 in the code that opens the
report.
 
Back
Top