UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Custom Error Handling, Office 2010    
 
   
crazybob62
post Mar 6 2012, 02:12 AM
Post #1

UtterAccess Member
Posts: 23



Hello

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!
Go to the top of the page
 
+
Alan_G
post Mar 6 2012, 04:06 AM
Post #2

Utterly Yorkshire and Forum/Wiki Editor
Posts: 15,895
From: Devon UK



Hi

Instead 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

Forms!NameOfForm!NameOfTextBoxOnForm

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
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 20th June 2013 - 12:13 AM