Full Version: Custom Error Handling
UtterAccess Forums > Microsoft® Access > Access Reports
I have a very simple database that has a few tables for keeping a few student course records. I have a VBA macro with the following data which simply opens a report in preview mode when the user clicks on the command button:
Private Sub cmdCompleteActiveTraining_Click()
DoCmd.OpenReport "rptTrainingAllActiveCompleteDateRange", acViewPreview, , , acWindowNormal
End Sub
The report is based on a query so when the user clicks the button, a couple of popup boxes appear one at a time asking for a date range. The results will display on a printable report. Here is my issue: If the user executes the command button and the pop-up boxes appear, if during this time the user hits the "Esc" key to cancel the execution, I get the Error Box: Run Time Error 2501 The OpenReport Action was cancelled. Then it asks to Continue/Debug/Cancel/Help.
What I want is a custom message, something like "Task Cancelled by User" then an OK button so the user could return to the menu screen where they were prior to executing the command button. Or if this is too tedious, when the person hits "Esc", it simply takes them back to the previous form screen.
Any help is appreciated!
nstead of using prompts as the criteria from the query itself (eg [Insert Name]), use a form for the user to enter the parameters and then use those values in the criteria of the query. If you replace [Your Prompt Here] in the queries criteria with
the values in the textbox will be used in the query, which means you can easily make sure that values are entered before trying to open your report - and hence no runtime error
This is a "lo-fi" version of UA. To view the full version with more information, formatting and images, please click here.