Is there a way to create an error log in Access

M

Mike Graves

I would like to keep a log of errors received by the database users so I can
determine any trends or anamolies.
 
N

Nick Coe \(UK\)

Store the error codes you trap in a table. I'm making this
up as I go along so be a bit circumspect about trying to
just paste it and use it.

You create yourself a new table tblErrHist with columns
something like:
ErrCode(Long) ErrWhen(Date/Time)

An autonumber PrimaryKey won't hurt either.

Create a function to store the error so that you can just
call it from each of your error traps.

Public Function StowErr(lngErrCode as long) as boolean

DoCmd.RunSQL "INSERT INTO tblErrHist ErrCode, ErrWhen "
_
& "VALUES " & lngErrCode & ", "
& Now() & ";"

StowErr=True

End Function

****************
Where you error trap in your code:

Dim bStowed as boolean
On Error GoTo ErrRoutine

~blah blah your code

ExitHere:
'Close rst's and nothingify as necessary
Exit Func/Proc/Sub

ErrRoutine:
Select Case Err.Number
Case ??

Case Else
MsgBox Err.Description
End Select

bStowed = StowErr(Err.Number)

GoTo ExitHere

End Func/Proc/Sub

That should do it, got a feeling I've forgotten something
though...
 
Top