OpenReport action was canceled - Error 2501

Hi all,

 

I have a routine behind a command button that opens a report.  And, of course, a 'cancel' event in the 'On No Data' property.  The purpose for the report is to display data to the user, based on who is logging in to the database (the report) before the application displays the Main menu.  So, obviously, there are two paths to go down.

 

Path 1:  The report indeed has data to display for the user logging in.  It displays the report > user closes the report > opens the Main Menu.

 

Path 2:  No data for the user logging in.  In this case, the message is displayed (from the 'On No Data' property) as intended.  When the User clicks the OK button to clear the message box, the Main Menu is displayed (again as intended).  However in this case, the Error Message pops up with the standard End/Debug options.

 

QUESTION:  Is there a way for me to ignore (and/or suppress) that error message dialog from popping up.  It is 'scary' to the casual users, and an annoyance to others.

 

Thanks in advance.  And, as usual, if there is simply a keyword you can use to 'point me' - I am happy to chase an answer from there.

 

FedBrad   

 

Answer
Answer
Trap and handle the error in the code which opens the report, e.g.

Const REPORTCANCELLED = 2501

On Error Resume Next
DoCmd.OpenReport "YourReport", View:=acViewPreview
Select case Err.Number
    Case 0
    ' no error
    Case REPORTCANCELLED
     ' anticipated error, so ignore
    Case Else
    ' unknown error, so inform user
    MsgBox Err.Description, vbExclamation, "Error"
End Select

_____________________
Ken Sheridan,
Newport, Shropshire, England

"Don't write it down until you understand it!" - Richard Feynman

6 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated April 3, 2024 Views 7,963 Applies to: