On No Data (1 Viewer)

mike60smart

Registered User.
Local time
Today, 00:14
Joined
Aug 6, 2017
Messages
1,904
see the code behind the button on form1.
Hi Arnelgp

I get the same error using your database?
 

Attachments

  • error.JPG
    error.JPG
    49.1 KB · Views: 83

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 07:14
Joined
May 7, 2009
Messages
19,230
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.
options.png
 

mike60smart

Registered User.
Local time
Today, 00:14
Joined
Aug 6, 2017
Messages
1,904
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
Hi Arnelgp

You are a star.

I never knew that is the setting to use.

It now works a treat. Many Thanks
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:14
Joined
Feb 19, 2002
Messages
43,257
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.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 00:14
Joined
Feb 19, 2013
Messages
16,607
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
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 19:14
Joined
Feb 19, 2002
Messages
43,257
I think Break on Unhandled errors is the default.

WARNING - be very careful when changing settings. Make sure you actually know what they do so you don't end up with a problem later.
 

NoLongerSet

Member
Local time
Yesterday, 19:14
Joined
Jul 13, 2021
Messages
31
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):

InformNoData.png
 

strive4peace

AWF VIP
Local time
Yesterday, 18:14
Joined
Apr 3, 2020
Messages
1,004
@mike60smart, adding on,

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
 

Users who are viewing this thread

Top Bottom