error handling

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a lot of sub procedures written for multiple forms. I want to create
a generic error handler that identifies the error number and error
description and instructs the user to contact the administrator. I do not
want them to have the option to debug or get into the coding in anyway. How
can I create this error handler once and have it activated anytime an error
occurs, regardless of what form they are using?
 
Heidi said:
I have a lot of sub procedures written for multiple forms. I want to
create a generic error handler that identifies the error number and
error description and instructs the user to contact the
administrator. I do not want them to have the option to debug or get
into the coding in anyway. How can I create this error handler once
and have it activated anytime an error occurs, regardless of what
form they are using?

You cannot. You can call a generic function in the error handling code of all
your procedures, but you have to put the error handlers in place. There is no
way to globally make this happen on all errors raised.

If you don't want them to have access to code then you should be giving them an
MDE, not an MDB.
 
In every sub or function you can add the error handler

Function MyFunctionName()
On error goto MyFunctionName_Err

Code .....

MyFunctionName_Exit:
Exit Function
MyFunctionName_Err:
msgbox error, "Contact Admin"
Resume MyFunctionName_Exit
End Function

To not allow the user enter the code you can do two things
1. Let the user run MDE database and not MDB
2. Install run time Access on their computer and not a full version of Access.
 
If you'd like to cheat. Open a form and create a command button and
utilize the wizard to make it perform some/any action. The wizard will
automatically create some very basic error handling. From there you'll
need to adapt the code under the _Error: label to do what you want it to
do. (Custom msgBox to user, log the error, etc.). Once that's done, you
can copy & post the components of the error handling code into which
ever functions/subs you need it in - just change the references.
 
You know that would be EXCEPTIONALLY nice to be able to designate a
generic handler.
 
I love to cheat -- thanks!

David C. Holley said:
If you'd like to cheat. Open a form and create a command button and
utilize the wizard to make it perform some/any action. The wizard will
automatically create some very basic error handling. From there you'll
need to adapt the code under the _Error: label to do what you want it to
do. (Custom msgBox to user, log the error, etc.). Once that's done, you
can copy & post the components of the error handling code into which
ever functions/subs you need it in - just change the references.
 
Thanks for the help... as you can probably tell, I'm new to creating
databases and programming, so the info you provided is greatly appreciated!
 
STOP! Before you do ANYTHING with creating a MDE be ***CERTAIN*** that
you backup the database under a different name FIRST. If you create a
MDE and then delete the original MDB file, you lose access to the
underlying VBA code. Very, very bad. Only solution is to his a good
Irish pub or better yet a Taverna. It won't bring back the source code,
but you won't care.
 
Ah, got it. I'll do some reading up on MDE's before I go forward. Thank you
for the info. And maybe I'll go to the Irish pub anyway.
 
Back
Top