Microsoft Access 2010 Bible

(Rick Simeone) #1

Part IV: Professional Database Development


922


l (^) The name of the control that was active at the time the error occurred (may be null if no
control is selected)
Function LogError (ProcName As String, _
ErrNum As Integer, ErrDescription) As Integer
Dim MyDB As DAO.Database
Dim tblErr As Table
Set MyDB = CurrentDB()
Set tblErr = MyDB.OpenTable(“tblErrorLog”)
tblErr.AddNew
tblErr(“TimeDateStamp”) = Now
tblErr(“ErrorNumber”) = ErrNum
tblErr(“ErrorDescription”) = ErrDescription
tblErr(“ProcedureName”) = ProcName
‘ The following may be null if no form
‘ or control is currently active.
tblErr(“FormName”) = Screen.ActiveForm. Name
tblErr(“ControlName”) = Screen.ActiveControl. Name
tblErr.Update
tblErr.Close
End Function
This simple subroutine adds to an existing table named tblErrorLog. What you do with the
data in this table is up to you. You may, for example, trigger a hard copy of the error log’s report at
the end of a session, or e-mail the report to a database administrator. A sophisticated application
would create tblErrorLog at the first instance of a logged error and then check for the existence
of tblErrorLog at the end of the session.
tblErrorLog contains the fields listed in Table 26.3.
TABLE 26.3


The Structure of tblErrorLog


Field Name Data Type
TimeDateStamp Date/Time
ErrorNumber Long Integer
ErrorDescription String 255
ProcedureName String 64
FormName String 64
ControlName String 64

The ProcedureName, FormName, and ControlName fields are 64 characters in length — long
enough to accommodate the longest possible names for these Access database objects. Error
descriptions are usually short, but you want to provide as much space as possible to hold them.
Free download pdf