I currently have a form with various reports. I am using the OnClick event with a command button and want to combine code to cancel the report when there is no data. This is what I'm using but I get a runtime error 2501 "the openreport action was cancelled". Any suggestions would be most appreciated. Thanks!
If NoData = True Then
MsgBox "There is no data to report.", vbOKOnly + vbInformation
Cancel = True
Else
DoCmd.OpenReport stDocName, acPreview
End If
If NoData = True Then
MsgBox "There is no data to report.", vbOKOnly + vbInformation
Cancel = True
Else
DoCmd.OpenReport stDocName, acPreview
End If