Freehal04 said:
I've been having a really hard time trying to figure out how to get
anything
but the simplest of codes to work. I've used code from people who swear
up
and down it works, i try to use it and nothing happens. There's always
some
kind of error.
This error handler might help some. Save it in a standard module and call it
like in the exanple below:
Public Function ErrorLog(objName As String, routineName As String)
Dim db As DAO.Database
Set db = CurrentDb
Open "C:\Error.log" For Append As #1
Print #1, Format(Now, "mm/dd/yyyy, hh:nn:ss") & ", " & db.Name & _
"An error occured in " & objName & ", " & routineName & _
", " & CurrentUser() & ", Error#: " & Err.Number & ", " &
Err.Description
Close #1
End Function
-------------------------------------------
Use it like this:
Sub MyExample()
On Error GoTo Err_Handler
' Your code here
Exit_Here:
Exit Sub
Err_Handler:
Call ErrorLog("frmMyForm", "MyExample")
Resume Exit_Here
End Sub
--------------------------------------------
It will create a file of errors on your C:\ Drive, named Error.log which
will tell you where, when, and where the errors are. The following code used
to be in the Access help files. It will build a table of Access and Jet
errors. Set a reference to DAO, (Do that for the code above too) and paste
this into a module:
Function AccessAndJetErrorsTable() As Boolean
Dim dbs As Database, tdf As TableDef, fld As Field
Dim rst As Recordset, lngCode As Long
Dim strAccessErr As String
Const conAppObjectError = "Application-defined or object-defined error"
On Error GoTo Error_AccessAndJetErrorsTable
' Create Errors table with ErrorNumber and ErrorDescription fields.
Set dbs = CurrentDb
Set tdf = dbs.CreateTableDef("AccessAndJetErrors")
Set fld = tdf.CreateField("ErrorCode", dbLong)
tdf.Fields.Append fld
Set fld = tdf.CreateField("ErrorString", dbMemo)
tdf.Fields.Append fld
dbs.TableDefs.Append tdf
' Open recordset on Errors table.
Set rst = dbs.OpenRecordset("AccessAndJetErrors")
' Loop through error codes.
For lngCode = 0 To 3500
On Error Resume Next
' Raise each error.
strAccessErr = AccessError(lngCode)
DoCmd.Hourglass True
' Skip error numbers without associated strings.
If strAccessErr <> "" Then
' Skip codes that generate application or object-defined errors.
If strAccessErr <> conAppObjectError Then
' Add each error code and string to Errors table.
rst.AddNew
rst!ErrorCode = lngCode
' Append string to memo field.
rst!ErrorString.AppendChunk strAccessErr
rst.Update
End If
End If
Next lngCode
' Close recordset.
rst.Close
DoCmd.Hourglass False
RefreshDatabaseWindow
MsgBox "Access and Jet errors table created."
AccessAndJetErrorsTable = True
Exit_AccessAndJetErrorsTable:
Exit Function
Error_AccessAndJetErrorsTable:
MsgBox Err & ": " & Err.Description
AccessAndJetErrorsTable = False
Resume Exit_AccessAndJetErrorsTable
End Function