runtime error when there is no data on rpt

ccox

Registered User.
Local time
Today, 12:29
Joined
Dec 27, 2005
Messages
32
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
 
It appears you are just NOT running the report if there is no data, remove the Cancel=True line and try it that way as it appears it is not needed.
 
I removed the line and now the report opens while there is no data.
 
So your IF is not working properly, or you have another OPENREPORT somewhere. Seems to me if the NoData is true, the OPENREPORT would not be executed by the supplied code. So there must be another OPENREPORT it is hitting.
 

Users who are viewing this thread

Back
Top Bottom