mfuller
asked on
Cancel Access Report Print When No Data Exists
I am printing multiple reports (8) from a Command Button using DoCmd.OpenReport for each report, however, all forms are not always required. I've tried entering "Cancel = True" on the "ON NODATA" event of the report but I always get an error message when the "ON NODATA" event is used. Is there some other way I can stop printing the blank reports when no data is available for that report?
pardon me... i mean behind the command button use On Error Resume Next...
sorry bout that...
dovholuk
sorry bout that...
dovholuk
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Leave the Cancel = True in the OnNOData event of the report. Then in the form that calls the event, (probably a button OnClick event) add error handling there. It should look something like this
Private Sub cmdMyReport_Click()
On Error GoTo err_MyReport
DoCmd.OpenReport "MyReport
ExitSub:
Exit Sub
err_MyReport:
If Err.Number = 2501 Then ' no data
Resume ExitSub
Else
MsgBox Err.Number & " " & Err.Description
Resume ExitSub
End If
Private Sub cmdMyReport_Click()
On Error GoTo err_MyReport
DoCmd.OpenReport "MyReport
ExitSub:
Exit Sub
err_MyReport:
If Err.Number = 2501 Then ' no data
Resume ExitSub
Else
MsgBox Err.Number & " " & Err.Description
Resume ExitSub
End If
ASKER
Thanks! It worked like a champ!
On Error resume next
and your problem should be solved...
dovholuk