locked
Error 0 RRS feed

  • Question

  • Greetings. I've been having issues resolving error 0 in a new error handler I've been trying to build. I realize that error 0 is the absence of an error but I keep getting a message box stating that I have an error 0. Here's the code on the form, followed by the code in my error handling module:

    Private Sub Command1_Click()
    10  If gcfHandleErrors Then On Error GoTo ErrorHandler
    
    20  'Call CloseDB TEMPORARILY DISABLED DURING TESTING
        Err.Raise Number:=71 'TEMPORARY TO ASSIST WITH TESTING ERROR HANDLING MODULE
    
    Exit_ErrorHandler:
    30  Exit Sub
    
    ErrorHandler:
        Dim FormName, CtrlName As String
    40  FormName = Screen.ActiveForm.name
    50  CtrlName = Screen.ActiveControl.name
    60  Call GlobalErrorHandler(FormName, CtrlName)
    70  Resume Exit_ErrorHandler
    
    End Sub

    Option Compare Database Option Explicit Public Const gcfHandleErrors As Boolean = True Sub GlobalErrorHandler(FormName, CtrlName) Dim db As DAO.Database Set db = CurrentDb Dim rs1 As Recordset Set rs1 = db.OpenRecordset("SELECT * FROM [T: Error Log]", dbOpenDynaset, dbFailOnError + dbSeeChanges) Dim UserID, ComputerID As String Call UpdateUserStatus(UserID, ComputerID) Dim DTMerr As Date DTMerr = Now() Dim ErrLn As Integer ErrLn = Erl Dim ErrNo As Long ErrNo = Err.Number Dim ErrDesc As String ErrDesc = Err.Description DoCmd.SetWarnings False With rs1 If Not (.EOF And .BOF) Then .MoveFirst .AddNew .Fields("Computer ID") = ComputerID .Fields("User ID") = UserID .Fields("Date and Time of Error") = DTMerr .Fields("Form") = FormName .Fields("Control") = CtrlName .Fields("Error Line") = ErrLn .Fields("Error Number") = ErrNo .Fields("Error Description") = ErrDesc .Update Else .AddNew .Fields("Computer ID") = ComputerID .Fields("User ID") = UserID .Fields("Date and Time of Error") = DTMerr .Fields("Form") = FormName .Fields("Control") = CtrlName .Fields("Error Line") = ErrLn .Fields("Error Number") = ErrNo .Fields("Error Description") = ErrDesc .Update End If End With DoCmd.SetWarnings True Dim MyError As Error Dim strMsg As String Debug.Print Errors.Count strMsg = "The following error has just occurred:" & vbCrLf & _ "Form Name: " & vbCrLf & _ "Control Name: " & vbCrLf & _ "Line Number: " & Erl & vbCrLf & _ "Error# " & Err.Number & vbCrLf & _ "Description: " & Err.Description For Each MyError In DBEngine.Errors With MyError MsgBox strMsg, vbCritical End With Next MyError

    End Sub


    Wednesday, March 29, 2017 2:49 PM

All replies

  • Hi,

    Did you step through the code? Which line is generating the error?

    Wednesday, March 29, 2017 3:20 PM
  • I notice that, inside your GobalErrorHandler procedure, you call another procedure, UpdateUserStatus.  If that procedure executes an On Error statement, it will clear the Err object.  Is that what's happening?


    Dirk Goldgar, MS Access MVP
    Access tips: www.datagnostics.com/tips.html

    Wednesday, March 29, 2017 6:24 PM