Based on some other threads I read, I tried the following code to trap error 2501, OpenReport Event Cancelled. This is from the NoData event of my report. It also resets the form controls to Null. No matter what code I try, the runtime error msgbox appears with the 'End' and 'Debug' buttons. All of my reference books provided code which didn't work. Any help will be greatly appreciated.
Private Sub Report_NoData(Cancel As Integer)
On Error GoTo Msg_Err
MsgBox "No data matched your criteria.", vbExclamation
DoCmd.CancelEvent
LineNull:
Forms!frmReportParameters![Combo6] = Null
Forms!frmReportParameters![Text10] = Null
Forms!frmReportParameters![Combo0] = Null
Forms!frmReportParameters![Combo2] = Null
Forms!frmReportParameters![Combo4] = Null
Forms!frmReportParameters![Text12] = Null
Forms!frmReportParameters![Combo21] = Null
Forms!frmReportParameters![Combo6].SetFocus
Exit Sub
Msg_Err:
Select Case Err.Number
Case 2501
MsgBox "Report was cancelled."
End Select
Resume LineNull
End Sub
Private Sub Report_NoData(Cancel As Integer)
On Error GoTo Msg_Err
MsgBox "No data matched your criteria.", vbExclamation
DoCmd.CancelEvent
LineNull:
Forms!frmReportParameters![Combo6] = Null
Forms!frmReportParameters![Text10] = Null
Forms!frmReportParameters![Combo0] = Null
Forms!frmReportParameters![Combo2] = Null
Forms!frmReportParameters![Combo4] = Null
Forms!frmReportParameters![Text12] = Null
Forms!frmReportParameters![Combo21] = Null
Forms!frmReportParameters![Combo6].SetFocus
Exit Sub
Msg_Err:
Select Case Err.Number
Case 2501
MsgBox "Report was cancelled."
End Select
Resume LineNull
End Sub