Tricks on Error Handling

PlasticsGuy

Registered User.
Local time
Today, 04:01
Joined
Jun 24, 2004
Messages
26
I am looking for hints and suggestions on Error handling. I know that errors are not a bad thing. The only thing bad about errors is how you handle them. In forms (which is my last real weak point) I get run time error #6. Is there a way I can isolate it and develop a way to handle that error so that the user will not have to adjust or wonder if it is something they did wrong? Is there a program either VBA or something else that I can use in my program to trap and inform me of what the errors mean and a possible way to handle them? :o
 
you can create your own error handling ... for example you can simply create a msgbox describing the error e.g.

Code:
public sub test()

On Error GoTo Err_ErrorHandler

   your sub goes here

Err_ErrorHandler:
MsgBox Err.Description, vbExclamation, "Error #" & Err.Number
Resume Exit_ErrorHandler

end sub
 
Will this work with all of the form events at once? Or do I need to enter the subs individually? :cool:
 
you should place error handling in every sub you create!
 
So on a sub there should be an error code?

Here is one example of one of my subs. Does this work?


Private Sub cmdDelete_Click()

On Error GoTo cmdDelete_ClickError

txtAdminNumber.SetFocus

If (Len(txtAdminNumber.Text) = 0) Then Exit Sub

If (AtLeastOneRecord("EQUIP")) Then
DoCmd.OpenQuery "qryDeleteEquipment"
Me.Requery
Else
CantPerform "equipment"
End If

Exit Sub

cmdDelete_ClickError:

ErrorHandler Err, Error$, "frmEquipment cmdDelete_Click"
DoCmd.close

End Sub

If so then am I going in the right direction? :rolleyes:
 
On the handler, could you say:

Code:
cmdDelete_ClickError:

If Err.Number = 6 Then
  'Enter your custom code here if you want specific operations to occur here.
Else
  msgbox Err.Number & ": " & Err.Description, 16, "Error"
End If
Exit Sub
 
Error Tracking Table

Hi there,

A trick you could do is log all of the errors in a database table. I use a single linked table (database is on the server). Any error in my front end application is automatically logged in a central location. I also use it to allow users to report dodgy data (that they have fudged :rolleyes: ).

Cheers,
Dave
 
Heres some code i use in my error handlers

The log_Error(err.number, err.description) is a public sub used to insert the error number, description and also the user into the error log table. It also presents an error msg telling the user to take a screen shot if possible and send to the administrator.

If statements are ok but quite often in complex subs a select case is much more readible given a few diff errors

error_handler:
Select Case err.number
case 6
'some code to handle specific error
case else
call log_error(err.number, err.description)
end select
 

Users who are viewing this thread

Back
Top Bottom