Solved

Resuming Default Error Handling After A Custom Response

Posted on 2002-06-18
4
323 Views
Last Modified: 2010-05-18

     I am using Access 97. I have run Repair Database and been told it was successful.

     When an error occurs, I want to run a sub to log the error in a table of such errors and then tell Access to give the error message it would give if there were no custom response -the default error message.

     The logging routine is an independent module. I have been calling it from an error handling routine triggered by On Error GoTo at the beginning of a subprocedure.  The clogging routine requires a "Response As Integer" argument;  I have passed 1, 0, or -1 as actual arguments from the calling routine. Near the end of the logging routine I have

Response = acDataErrDisplay

The procedure does execute pass that point(I put in a MsgBox to check). From Debug.Print it is clear that this line does change the value of the Response argument passed to the logging routine, and that it changes it differently for acDataErrContinue v. acDataErrDisplay.

     If I try to enter a "Response =" in an event procedure run from a control or form event, I get "variable not defined",  except  in an event procedure for the form's OnError event.

     When can a Response argument be used to control Access's default error messages? Is it available only in code run from a form's Error event rather than an On Error statement? If so, why?

     Is there a better way to pass the Response argument to the logging routine?

     What triggers a form's Error event? Can an error in the form's class module?

     Is there some other statement(Resume or other) or code which I can use to log the error and then return to default error handling?

     I know that I could create a custom MsgBox with the error number and description, and with the Help button through the HelpFile and HelpContextID properties. Could I also add Debug and End buttons to such a box?

But first I would like to know if there is a way to simply tell Access to give the default error message.

CaseCounter
0
Comment
Question by:CaseCounter
  • 2
  • 2
4 Comments
 
LVL 8

Accepted Solution

by:
dovholuk earned 200 total points
ID: 7091647
wow, that's a lot of questions... i'll do my best (although i gotta go to bed soon! :-) )

>If I try to enter a "Response =" in an event procedure run from a control or
>form event, I get "variable not defined", except  in an event procedure for
>the form's OnError event.
that's right... if you look at the declaration of the form's onerror event it should look like:

Private Sub Form_Error(DataErr As Integer, Response As Integer)

the reason you can't use Response anywhere except here is because the "Response" variable is declared in the Sub (as shown above by "Response As Integer")  this is ONLY available during a form's onError event, unless you specifically create a whole error handling routine (as i do often) that has similar properties...

>When can a Response argument be used to control Access's default error messages?
well, you can call it whatever you want, but you need to (as described above) create a WHOLE NEW error handler... here's what i do a lot of:

' Some routine that's running

On Error Goto MyEventHandler
'more code
'more code
'more code

'Exit routine "normally" here
MyEventHandler:
Select Case MyCustomErrorHandlingRoutine(err.number)
     case 0:
           'situation aok now, resume routine
           resume
     case 1:
           'situation expected, just resume next
           resume next
     case 2:
           'something's WAY out of wack. exit this routine and tell the user
           msgbox "Hey buddy... you screwed the pooch! try again"
           'exit routine here
end select

here the custom error handler only takes one argument (the error number) and it decides what to do, what messages to display etc. the best part is that it's entirely customized, so you can decide how you want to handle the whole situation in code... make sense? (hopefully)

>Is it available only in code run from a form's Error event rather than an
>On Error statement? If so, why?
answered above.

>Is there a better way to pass the Response argument to the logging routine?
better way? well since you need to create the custom error handler, it's up to you as to how you implement it... the code i posed above is only one of MANY ways you could handle things...

>What triggers a form's Error event?
that's a good question.  i don't know for sure... what i do know is that when you enter a value such as "this is an error" into a numerical field, you'll get an error event. also, as far as i can tell, it'll only fire when a control initiates an error... however, if there is before/after update events (or onchange etc events) that cause an error, AND the event itself does NOT have an error handler in the routine, the form's onError event WILL fire... take this for instance...

you have a form with 2 controls, one formatted as numeric, the other as text. the numeric field (called text0) has an afterupdate event as follows:

me.text0 = "bobby"

this will fail, as text0 is formatted as "numeric" so when you try to set it to text, access will cause an error... this WILL get picked up by the form's onError event... now if the same event has instead:

on error resume next 'just go to the next line of code
me.text0 = "bobby"

then the error will be processed, and your numeric field will have the INVALID value of "bobby"... make sense again? (it's getting confusing, i know!) sorry.

>Can an error in the form's class module?
yes, as answered above

>Is there some other statement(Resume or other) or code which I can use to log
>the error and then return to default error handling?
just create a self-defined (custom) error handling routine, and you'll be all set.

>I know that I could create a custom MsgBox ... Could I also add Debug and End buttons...?
WHY??? you don't want your users debugging your code, do you? the idea behind handling errors is so a user doesn't need to worry about this type of thing... however, yes. if you make a custom form, you can create any buttons you want to produce any functionality you want... although, i don't know how you'd mimic the "debug" option that is built into vb... my advice is to not worry about it. handle the errors as you are the "experienced" one and don't let the users NEAR your code!!! :)

>first I would like to know if there is a way to simply tell Access to give
>the default error message.
well the easiest way (that i can think of at least) is to use a custom error handler that takes two parameters. such as:

Function test(ErrDescription As String, Optional DefaultMessage As Boolean)

If DefaultMessage = True Then
   MsgBox ErrDescription
Else
   MsgBox "my custom error message"
End If
End Function

then you can specify if you want to display the error or not...

hope this all makes sense.. i got to go to bed now!

dovholuk
0
 

Author Comment

by:CaseCounter
ID: 7097268
With Thanks

           The information didn't provide as simple and easy way to do everything that I had hoped for, but it was very helpful, including the information about the On Error event.

          One further question about that. Is it possible to trap a specific description rather than "Application-defined or object-defined error" for the errors that trigger it? The Access Help says that this category includes "host-created" errors like those in visual basic caused by forms, reports etc. The Err object seems to contain only Visual Basic(and some DAO) errors. Is there a way to get at the messages Access provides for form and control errors?

                                              Yours Sincerely,
                                                       CaseCounter




0
 
LVL 8

Expert Comment

by:dovholuk
ID: 7097345
>The information didn't provide as simple and easy way to do everything that I had hoped for
i understand. unfortunately, sometimes the answer to a problem is NOT the answer people want to hear. sounds like this is the case... sorry.


i don't know how to access the form level errors. all i can tell you is to set the response to 1, and it'll display the "stock" error. but i bet you knew that.

dovholuk
0
 

Author Comment

by:CaseCounter
ID: 7099706
Thanks. I'm not sure anyone could have completely solved my problem, but you did clarify the situation a great deal.

               Counter
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now