Problems when report has no data

ccox

Registered User.
Local time
Today, 00:55
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 "No data to report.", vbOKOnly + vbInformation
Cancel = True
Else
DoCmd.OpenReport stDocName, acPreview
End If
 
I would use the query that the report is based on as follows
in the on click event of the button that runs the report i would do this
(before the report is called)
Dim Nodata as string

Nodata = nz(dlookup("[your column]","[yourreportquery]"),"")

If Nodata = "" then
msgbox "No Data Available etc",vbinformation,"No Data Available"
exit sub
end if

If the query returns a null value (no data) then the event will be exited and the report will not be run
 
That appears to have worked!!! Thank you so much!
 

Users who are viewing this thread

Back
Top Bottom