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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to trap an error that can occur in numerous events?

Status
Not open for further replies.

annie52

Technical User
Mar 13, 2009
164
US
We're having a lot of network issues lately. I'd like to be able to personalize Error 3043 ("Your network access was interrupted. To continue, close the database, and then open it again.")

I don't know how to trap the error because it can occur while the user is doing any number of things. Where do I put this code?
 
I make a standard error handler, and then beef up the select case to put lots of specific messages depending on the error. You can call this from any/all events.
Code:
Function ErrHandler(lngErrNum As Long, strErrDesc As String, strWhereFrom As String) As Boolean
On Error GoTo errLbl
    Dim strMsg As String
    Dim strSpecific
    ErrHandler = True
    Select Case lngErrNum
      Case -2147352567
        strSpecific = "There is no item selected."
    End Select
    strMsg = strMsg & "There has been an error in the application." & vbCrLf & vbCrLf
    strMsg = strMsg & "Error Number: " & lngErrNum & vbCrLf
    strMsg = strMsg & "Error Description: " & strErrDesc & vbCrLf
    strMsg = strMsg & strSpecific & vbCrLf
    strMsg = strMsg & "Error Location: " & strWhereFrom & vbCrLf
       
    MsgBox strMsg, vbInformation, "Error Log."

Exit_Error:
    Exit Function
errLbl:
    ErrHandler = False
    MsgBox Err.Description, vbExclamation, "Error detected."
    Resume Exit_Error

End Function

' Call as follows from another procedure
'  On Error GoTo errLbl:
'
'    Exit Sub
'errLbl:
'   Call errHandler(err.Number, err.Description, "Error in xxx")
 
Hi MajP. I do call a standard error handler from various events. The problem is, I can't anticipate ALL of the events where this error may pop up. I'm wondering if there's a way to tell the application to run certain code anytime this particular error arises.
 
There is no native way that I know of. But even if you had thousands of events, you still should be able to put error checking in all events. There are some tools to automate doing that. There are several free tools on the web.
 
Okay, thanks for getting back to me.
 
If you want to cover all possibilities why not simply do what you want at the form level?
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Dim Message As String
 If DataErr = 3043 Then 'Connection dropped
 Message = "Your message goes here"
 Response = MsgBox(Message, vbExclamation, 
 "Connection  Dropped")
 Response = acDataErrContinue
 'Do whatever else here
End If
End Sub


The Missinglinq

Richmond, Virginia

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top