Error handling code

J

JRF

I have an application that was handed to me and requested that I add error
handling code to all forms and modules within the application, there was
none to begin with.

Events such as below do not have any error handling.

** Event Example 1

Private Sub cmdReports_Click()

DoCmd.OpenForm "frmARDBReports", acNormal

End Sub


Though it seems like a bad practice, I would like to add common syntax to
all events, for example:


** Event Example 2

Private Sub cmdReports_Click()

On error goto err_Action

DoCmd.OpenForm "frmARDBReports", acNormal

Exit_err_Action:
Exit Sub

err_Action:
ErrorRoutine 'calls uniform error message function
Resume Exit_err_Action

End Sub


By adding the same error handling code to all events, as in Event Example 2,
will this actually create more problems than solving, with addition of the
same error handling code to all Access events within the application.
 
R

RobFMS

Its a good practice to have error handling in all code so that you provide
the user with a good "user experience" when the user runs your application.

In some cases, it may not be necessary to display a message on every error.
There might be some cases that On Error Resume Next might be applicable.



--
Rob

FMS Professional Solutions Group
http://www.fmsinc.com/consulting

Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
 
J

JRF

Will using the same syntax for every event procedure cause problems. I just
don't want to get involved in a unique reference for each error handling
incident. For example, I want to avoid creating unique error handling code
for each event, as in Ex1,2,3. I just want to use the same syntax for each
event handler as in Ex4.

Ex1
On error goto err_Action_somethingorother
DoCmd.OpenForm "frmARDBReports", acNormal
Exit_err_Action_somethingorother:
Exit Sub
err_Action_somethingorother:
ErrorRoutine 'calls uniform error message function
Resume Exit_err_Action_somethingorother

Ex2
On error goto err_Action_moresomethingorother
DoCmd.OpenForm "frmARDBReports", acNormal
Exit_err_Action_moresomethingorother:
Exit Sub
err_Action_moresomethingorother:
ErrorRoutine 'calls uniform error message function
Resume Exit_err_Action_moresomethingorother

Ex3
On error goto err_Action_evenmoresomethingorother
DoCmd.OpenForm "frmARDBReports", acNormal
Exit_err_Action_evenmoresomethingorother:
Exit Sub
err_Action_evenmoresomethingorother:
ErrorRoutine 'calls uniform error message function
Resume Exit_err_Action_evenmoresomethingorother

Ex4
On error goto err_Action_samesyntax
DoCmd.OpenForm "frmARDBReports", acNormal
Exit_err_Action_samesyntax:
Exit Sub
err_Action_samesyntax:
ErrorRoutine 'calls uniform error message function
Resume Exit_err_Action_samesyntax
 
R

Rick Brandt

JRF said:
Will using the same syntax for every event procedure cause problems. I just
don't want to get involved in a unique reference for each error handling
incident. For example, I want to avoid creating unique error handling code
for each event, as in Ex1,2,3. I just want to use the same syntax for each
event handler as in Ex4.

Using a consistent error handler construct (same line labels etc.) is a
good practice and causes no issues that I am aware of.
 
M

Marshall Barton

JRF said:
I have an application that was handed to me and requested that I add error
handling code to all forms and modules within the application, there was
none to begin with.

Events such as below do not have any error handling.

** Event Example 1

Private Sub cmdReports_Click()

DoCmd.OpenForm "frmARDBReports", acNormal

End Sub


Though it seems like a bad practice, I would like to add common syntax to
all events, for example:
[]

Gee, Rob is being a bit too modest here. FMS Inc. sells
several Access programmer productivity tools, one of which
will process your entire application and add basic error
handling code to every procedure in one fell swoop. Check
out their web site (in Rob's sig) for details.
 
R

RobFMS

Thanks for the lead-in Marsh.

The tool is called Total Visual CodeTools:
http://www.fmsinc.com/products/CodeTools/index.html



--
Rob

FMS Professional Solutions Group
http://www.fmsinc.com/consulting

Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Marshall Barton said:
JRF said:
I have an application that was handed to me and requested that I add error
handling code to all forms and modules within the application, there was
none to begin with.

Events such as below do not have any error handling.

** Event Example 1

Private Sub cmdReports_Click()

DoCmd.OpenForm "frmARDBReports", acNormal

End Sub


Though it seems like a bad practice, I would like to add common syntax to
all events, for example:
[]

Gee, Rob is being a bit too modest here. FMS Inc. sells
several Access programmer productivity tools, one of which
will process your entire application and add basic error
handling code to every procedure in one fell swoop. Check
out their web site (in Rob's sig) for details.
 
B

Brendan Reynolds

Earlier versions of VBA used to require unique label names, and the code
produced by the control wizards still does that, e.g. "Exit_Command0_Click:"
and "Err_Command0_Click:", but this is no longer necessary in recent
versions. In Access 97 and later you can safely use the same label names in
different procedures, labels only need to be unique within a procedure, so
you can use ExitProcedure:" and "ErrorHandler" in all your procedures. Is
that what you meant?

--
Brendan Reynolds (MVP)
http://brenreyn.blogspot.com

The spammers and script-kiddies have succeeded in making it impossible for
me to use a real e-mail address in public newsgroups. E-mail replies to
this post will be deleted without being read. Any e-mail claiming to be
from brenreyn at indigo dot ie that is not digitally signed by me with a
GlobalSign digital certificate is a forgery and should be deleted without
being read. Follow-up questions should in general be posted to the
newsgroup, but if you have a good reason to send me e-mail, you'll find
a useable e-mail address at the URL above.
 
J

JRF

I am familiar with FMS, they are prevalent in my monthly issues of SQL VB
ACCESS Advisor, good product offering.

RobFMS said:
Thanks for the lead-in Marsh.

The tool is called Total Visual CodeTools:
http://www.fmsinc.com/products/CodeTools/index.html



--
Rob

FMS Professional Solutions Group
http://www.fmsinc.com/consulting

Software Tools for .NET, SQL Server, Visual Basic & Access
http://www.fmsinc.com

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Marshall Barton said:
JRF said:
I have an application that was handed to me and requested that I add error
handling code to all forms and modules within the application, there was
none to begin with.

Events such as below do not have any error handling.

** Event Example 1

Private Sub cmdReports_Click()

DoCmd.OpenForm "frmARDBReports", acNormal

End Sub


Though it seems like a bad practice, I would like to add common syntax
to
all events, for example:
[]

Gee, Rob is being a bit too modest here. FMS Inc. sells
several Access programmer productivity tools, one of which
will process your entire application and add basic error
handling code to every procedure in one fell swoop. Check
out their web site (in Rob's sig) for details.
 

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