Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Err.Description Is Null 1

Status
Not open for further replies.

grgimpy

Programmer
Nov 1, 2006
124
US
I wrote up a generic error handler that I want to use to handle all errors in each sub routine of my form. For some reason it never gives me an error description. I've also tried the "Error$" instead of "Err.Description" but have no luck. Any help would be greatly appreciated. Here's the code:

Code:
Private Sub ErrRoutine()
On Error GoTo Err_Handler
'This sub routine sends an e-mail to notify
'the engineer of a database error and gives
'user an error message.

    MsgBox "Error " & Err.Number & " - " & Err.Description, _
        vbOKOnly Or vbCritical

    Call EMailNames
    DoCmd.SendObject , "", "", strErrEmail, "", "", _
        "Nickel/Gold Plating Database Error!", _
        Now() & vbCrLf & vbCrLf & _
        "Error " & Err.Number & " - " & Err.Description & vbCrLf & vbCrLf & _
        "Sub Routine: " & strErrSubRoutine & " in the Main Page.", _
        False, ""

Exit_Handler:
    Exit Sub
Err_Handler:
    MsgBox "Error " & Err.Number & " - " & Err.Description, _
        vbOKOnly Or vbCritical
    Resume Exit_Handler
End Sub
 
Does it give an error number ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
yes, but i just realized that the error number is always 0. so i guess that makes my question: why is my error number always 0?
 
The Err object is reinitialized on each procedure entry, I guess.
you may try this:
Code:
Private Sub ErrRoutine(ErrNumber As Long, ErrDescription As String)
On Error GoTo Err_Handler
MsgBox "Error " & ErrNumber & " - " & ErrDescription, _
       vbOKOnly Or vbCritical
' your mail stuff here ...
Exit_Handler:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " - " & Err.Description, _
       vbOKOnly Or vbCritical
Resume Exit_Handler
End Sub

And in the other procedures:
Code:
Sub tstError()
On Error GoTo myHandler
' some stuff here raising an error
myExit:
Exit Sub
myHandler:
Call ErrRoutine(Err.Number, Err.Description)
Resume myExit
End Sub

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
that worked perfectly. thanks for the quick response and help!

 
The Err object is cleared when you hit a "Resume..." statement. My guess is that was the cause of the problem...

Ed Metcalfe.

Please do not feed the trolls.....
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top