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

What resets the Error object ??

Status
Not open for further replies.

mordja

Programmer
Apr 27, 2004
294
GB
Hi,

Ive written a simple module which I now use to log any errors that any event may trigger.

Code:
Option Compare Database
'Provides simple error logging facilities

Public Const strLogTable As String = "tblErrorLog"

Public Function logError(ByVal strObjectSource As String, ByVal intErrorNumber As Integer, ByVal strErrorDescription As String)
On Error GoTo Err_logError

Dim rst As ADODB.Recordset

'Adds error occurance to log table
DoCmd.SetWarnings False

Set rst = New ADODB.Recordset
rst.ActiveConnection = CurrentProject.Connection
rst.CursorType = adOpenDynamic
rst.LockType = adLockOptimistic

strSQL = "Select * From " & strLogTable

rst.Open strSQL
With rst
        .AddNew
            .Fields.Item(0).Value = strObjectSource
            .Fields.Item(1).Value = intErrorNumber
            .Fields.Item(2).Value = strErrorDescription
            .Fields.Item(3).Value = Now
        .Update
End With

rst.Close
Set rst = Nothing

DoCmd.SetWarnings True

Exit_logError:
    Exit Function
    
Err_logError:
    MsgBox "Error In ErrorLog.logError () :" & Err.Description
    Resume Exit_logError
    
End Function

It works as you would expect. However on the following form load event
Code:
Private Sub Form_Load()
On Error GoTo ErrorHandler

Me.FilterOn = True

Exit Sub

ErrorHandler:
    If Err.Number <> 2001 Then
        MsgBox "Error In Form_Sterling_frmUploadedMTDAdjustments.Form_Load () :" & Err.Description
    Else
        DoCmd.Close acForm, "Sterling_frmUploadedMTDAdjustment", acSaveNo
    End If
    Call logError("Form_Sterling_frmUploadedMTDAdjustments.Form_Load", Err.Number, Err.Description)

End Sub
I noticed that If I make the call to logerror before my if statement then when the if statement is executed the err.Number is always 0, can anyone explain ??

Thanks

Mordja
 
Are you sure you are calling your Proc when you have an error as you would normally get an err.number = 0 when you have no errors.

The only ways I know for an error to be cleared from the err object is if you call err.clear or the error is reoslved.
 
mordja,

because you are submitting to the logerror function before your if statement you are infact sending the information from the Error Object, which will populate your table.

Inside this function you are again setting the error event handler, so therefore you are resetting the Err object.

Not sure why you are doing this mind

strSQL = "Select * From " & strLogTable
rst.Open strSQL

as
Code:
rst.Open strLogTable

does the same thing.

Danny

Never Think Impossible
 
dmksas,

Hey thanks should have realised, and as to why Ive used select * from etc, never really thought about it, i will use rst.Open strLogTable from now on !

Mordja
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top