Error Trapping

=TB=

Registered User.
Local time
Today, 18:11
Joined
Aug 13, 2002
Messages
68
When is it proper to trap for errors, is it a good habit to trap for errors in every procedure or is it not needed.

Can anyone explain error trapping a little more to me, it's something I have not really dealt with before.

Thanks in advance.
 
I recommend that all of your subs and function have error trapping. Below is a sample of error handling in a sub.
Code:
	Private Sub btnOpenInvoices_Click()
	On Error GoTo Err_btnOpenInvoices_Click
   
	'Open frmInvoices form
	DoCmd.OpenForm "frmInvoices", acNormal, , , acFormAdd, acWindowNormal
   
	Exit_btnOpenInvoices_Click:
	    Exit Sub
   
	Err_btnOpenInvoices_Click:
	    MsgBox Err.Number & ": " & Err.Description
	    Resume Exit_btnOpenInvoices_Click
   
	End Sub
Check out the "error handling in run-time applications" section in the Access help files.

HTH
 
Thankyou
 
ghudson said:
Code:
	Exit_btnOpenInvoices_Click:
	    Exit Sub
   
	Err_btnOpenInvoices_Click:

In this section it's a good idea to set some objects (if you've used them to Nothing)

e.g. (although these objects have just been added)

Code:
Exit_btnOpenInvoices_Click:
    Set rs = Nothing
    Set db = Nothing
    Exit Sub
   
Err_btnOpenInvoices_Click:
 

Users who are viewing this thread

Back
Top Bottom