generic error handling

J

Josh

Just so that user doesn't get dumped to code window, I'd like start adding
generic error handling to my forms. I've seen examples of generic error
handling, some as simple as the basic button wizard:

On Error GoTo Err_Command70_Click

My question, can I have the same "name" (for lack of a better word) for all my
generic error handlers? In other words, have

Private Sub Form_Current()
On Error GoTo ErrHandler
rest of sub

Private Sub Form_BeforeUpdate()
On Error GoTo ErrHandler
rest of sub

or will I need to have a different GoTo "name" for each event, such as:

Private Sub Form_Current()
On Error GoTo Err_Form_Current
rest of sub

Private Sub Form_BeforeUpdate()
On Error GoTo Err_Form_BeforeUpdate
rest of sub

Thanks
 
A

Allen Browne

Use the same name Josh.

Access 1 and 2 required application-wide unique labels, so that's why you
still see code like that, but for the last 10 years you have been able to
use a generic label such as ErrHander in every routine if you wish.

Couple of suggestions:
a. Consider logging the errors.
Users can rarely tell you what error they saw, so call a generic error
handler function that logs the error (except for obvious ones such as 2501.)
This is useful for debugging, support, maintenance, and catching issues
users don't tell you about. A simple example:
Error Handling in VBA
at:
http://allenbrowne.com/ser-23a.html

b. Consider the MZTools add-in
mztools.com have a VBA add-in that gives you a toolbar button that lets you
add the error-handler code to any routine with a mouse click. You can
configure what it says, and have it specify the name of the routine tool.
 
J

Josh

I'll try logging in the near future, for right now the MZTools looks good.
I downloaded it, I see it also has msgbox assistant & some sort of ADO
Connection String wizard or helper. (In addition to lots of other tools).

Thanks!
 
D

david epsom dot com dot au

I never used Access 1, but Access 2.0 required module-level
unique labels (not application unique)- and module level
unique line numbers (but the numbers could be larger than 64K).

Inherited from MS BASIC, which originally had BASIC style
exception handlers - you could jump from anywhere to anywhere.

But as far as I know Access never supported BASIC style
exception handlers.

I still remember the irritation of my father when he had
to try to port code from traditional BASIC (which used
common line numbers as methods for dynamic objects) to
MS BASIC 6 or 7: You couldn't call line nnnn from anywhere,
but you couldn't re-use the line number either, so you
couldn't create a remote entry point.

He gave up in disgust and went to Power Basic, a fully
compiled BASIC which supported modern hardware and would
accept classic BASIC syntax and automatically handle
code segments.

BTW, in Access Basic, if you carelessly typed "Exit Sub"
in a Function, you didn't get an error, and no message
box grabbed focus. It just corrected the text.


(david)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top