custom error handling with macros in access 2010

How can I assign custom error handling using Macros in access 2010 to show specific messages based on the error...with time being a significant factor?
DavidLechmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
Actual Macros or VBA code ?

mx
0
mbizupCommented:
You can't do much with macros, but with VBA, something like this:

Sub YourSubName()
    On Error Goto EH
   
          ' Your code goes here

    Exit Sub   '<--- Exits normally if there is no error

EH:   '<--- This begins the error handler

    SELECT Case Err.Number

           Case 1234  '<--- Special Handling for specific error numbers
                 Do something
                 Resume Next   '<--- this returns to the line of code following the error and continues from there
            Case 4567 

                   Do Something else

              Case Else

                     MsgBox "Error " & Err.Number & ": " & err.description

            End select

End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DavidLechmanAuthor Commented:
how do I create the number reference list? What part of the texts you provided are examples and/or instructions vs actual code? What would I replace with custom data? Thank you!
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

mbizupCommented:
The numbers 1234 and 4567 are examples (hypothetical error numbers).  You would replace them with actual numbers of errors that you want special handling for.

The lines "Do something" and "Do something else" are examples as well.  You would replace them with lines or blocks of code that handle the errors as you want.

Everything else is "real code".


As far as creating a 'list' of errors... the method I posted here uses a general error message (the Case Else section) to handle *most* errors.

The numbers would be special handling for errors that you might expect to happen in certain while performng specific functions.  


For example, a sub that sends out an Outlook email will encounter a specific error if the user cancels the email.  So that sub should provide error handling for that specific error and if needed use 'resume next' to run the sub to completion after a user-cancelled email.
0
DatabaseMX (Joe Anderson - Microsoft Access MVP)Database Architect / Systems AnalystCommented:
DavidLechman:
I highly recommend you start with the articles below to get some background on error handling.  Once you complete these, you will pretty much have it under control.

Good white paper on error handling
http://www.fmsinc.com/tpapers/vbacode/Debug.asp   

Runtime Error Handling
http://msdn.microsoft.com/en-us/library/bb256425.aspx 

more on error handling
http://allenbrowne.com/ser-23a.html 

Global error handler - awesome product - read my review.
http://www.everythingaccess.com/vbwatchdog.htm      

Discussion of field validating - Form BeforeUpdate event and Form Error event ....
http://www.experts-exchange.com/Microsoft/Development/MS_Access/Q_26898496.html#a35173496

mx
0
Jeffrey CoachmanMIS LiasonCommented:
MZ Tools has a utility that will automatically insert your custom Error Handling in your code.
http://www.mztools.com/v3/mztools3.aspx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.