So I've searched and tried different codes to prevent this error from popping up. I was able to get the pop-up msg to display, but then I keep getting 2501.
Basically: I have a report that I call upon via a form that is used by a query to populate the report.
On the report NoData Event:
I think that's fine. The issue comes on the button in the form. I've tried 2 different codes:
That didn't work so I tried:
Both of them still show the 2501 error after the msg pop-up.
Where is the issue and which one would be better to use?
Thanks in advance.
Basically: I have a report that I call upon via a form that is used by a query to populate the report.
On the report NoData Event:
Code:
Private Sub Report_NoData(Cancel As Integer)
MsgBox "No data to Display"
Cancel = True
End Sub
I think that's fine. The issue comes on the button in the form. I've tried 2 different codes:
Code:
Private Sub btnReport_Click()
DoCmd.OpenReport "rptByLocations", acViewPreview
If Err.Number <> 2501 Then
MsgBox Err.Description, vbExclamation, "Error: " & Err.Number
Resume Next
End If
That didn't work so I tried:
Code:
Private Sub btnReport_Click()
DoCmd.OpenReport "rptByLocations", acViewPreview
On Error GoTo ErrorHandler
ErrorHandler:
Select Case Err
Case 2501
MsgBox "No data to display"
DoCmd.Hourglass False
Case Else
MsgBox Err.Description
DoCmd.Hourglass False
End Select
End Sub
Both of them still show the 2501 error after the msg pop-up.
Where is the issue and which one would be better to use?
Thanks in advance.