Hi,
Ive written a simple module which I now use to log any errors that any event may trigger.
It works as you would expect. However on the following form load event
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
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
Thanks
Mordja