Rmaster2022
Member
- Local time
- Today, 14:38
- Joined
- Apr 1, 2022
- Messages
- 32
I have the following code for a “On No Data” event:
Private Sub Report_NoData(Cancel As Integer)
MsgBox "Nothing to print.", vbCritical, "No data"
Cancel = True
End Sub
On all of my reports, if there is no data, when I close the message box, I get another window that says: “The Open Report action was canceled,” with an OK button to close.
However, when I close the message box on one of my reports, I get the runtime error 2501 with the end, debug, and help buttons. One difference on this report is that it is based on a parameter query that asks for a year. I’m afraid this window will confuse the users.
I tried this code but got the same response.
'------------------------------------------------------------
' Macro1
'------------------------------------------------------------
Function Macro1()
On Error GoTo Macro1_Err
Beep
MsgBox "There is no data to print.", vbCritical, "No data."
DoCmd.CancelEvent
Macro1_Exit:
Exit Function
Macro1_Err:
MsgBox Error$
Resume Macro1_Exit
End Function
As you can probably tell, this is a conversion from a macro. I am very much a beginner in VBA, so I probably need the full code.
Also, I’m aware that I should have some error handling code included in the code I copied that I have for all the other reports. What should that code be?
Private Sub Report_NoData(Cancel As Integer)
MsgBox "Nothing to print.", vbCritical, "No data"
Cancel = True
End Sub
On all of my reports, if there is no data, when I close the message box, I get another window that says: “The Open Report action was canceled,” with an OK button to close.
However, when I close the message box on one of my reports, I get the runtime error 2501 with the end, debug, and help buttons. One difference on this report is that it is based on a parameter query that asks for a year. I’m afraid this window will confuse the users.
I tried this code but got the same response.
'------------------------------------------------------------
' Macro1
'------------------------------------------------------------
Function Macro1()
On Error GoTo Macro1_Err
Beep
MsgBox "There is no data to print.", vbCritical, "No data."
DoCmd.CancelEvent
Macro1_Exit:
Exit Function
Macro1_Err:
MsgBox Error$
Resume Macro1_Exit
End Function
As you can probably tell, this is a conversion from a macro. I am very much a beginner in VBA, so I probably need the full code.
Also, I’m aware that I should have some error handling code included in the code I copied that I have for all the other reports. What should that code be?