what?!, i don't get that error.
wait... goto VBA, and on the menu Tools->Options, do you have this (yellow border) on your option?
if anything then click the option that i have and try your button again.
what?!, i don't get that error.
wait... goto VBA, and on the menu Tools->Options, do you have this (yellow border) on your option?
if anything then click the option that i have and try your button again. View attachment 101915
In summary,
When you call an event that might be cancelled whether via a call or something like DoCmd.OpenReport, the calling procedure needs to have code to handle error 2501.
To follow up on arnels comments- I’ve been caught out with the wrong setting as well. You never want to use break on all errors as it will still break on handled errors. Break in class module can be a useful temporary debugging setting as otherwise the error will appear when the class is estantiated so you then need to step through to find the actual location of the error
I wrote a series of articles about my custom PreviewReport function that I use to wrap DoCmd.OpenReport. One of those articles focused on the "'OpenReport' action was canceled" error message and how I deal with it. Finally, I wrote an article with code for a simple function, InformNoData(), that you can call directly from the Report's On No Data section of the property sheet, potentially keeping your report lightweight (i.e., no VBA code-behind):
If you want the user to get a message when a report has no data, there are 2 places to possibly do it
in the calling program
in code behind the report
before DoCmd.OpenReport, perhaps you want to consider:
1. if report doesn't have any data, an error will be returned when Access tries to open it ... so maybe preface OpenReport with "On Error Resume Next", which will cause calling program to skip errors -- and then if an error happens, you can give a message that there wan't any data, or report couldn't be opened for some other reason -- unless what you opened already did that.
2. If report being opened has no data and has a NoData event, that will be executed, so opportunity to provide information to the user as to why no report is displayed. @NoLongerSet suggests a generic procedure