Sub CreateErrorsTable()
'The following procedure creates a table in Microsoft Access containing the error codes
'and strings used or reserved by Visual Basic. The table doesn't include Data Access
'Objects (DAO) errors.
'Visual Basic reserves a portion of the first thousand possible error numbers, so this
'example considers only error numbers between 1 and 1000. Other error numbers are
'reserved by the Microsoft Jet database engine, or are available for defining custom errors.
Dim dbs As Database, tdf As TableDef, fld As Field
Dim rst As Recordset, lngCode As Long
Const conAppObjectError = "Application-defined or object-defined error"
' Create Errors table with ErrorNumber and ErrorDescription fields.
Set dbs = CurrentDb
Set tdf = dbs.CreateTableDef("Errors")
Set fld = tdf.CreateField("ErrorCode", dbLong)
tdf.Fields.Append fld
Set fld = tdf.CreateField("ErrorString", dbText, 255)
tdf.Fields.Append fld
dbs.TableDefs.Append tdf
Set rst = dbs.OpenRecordset("Errors")
For lngCode = 1 To 1000 ' Loop through first 1000 Visual Basic error codes.
On Error Resume Next
Err.Raise lngCode 'Raise each error.
DoCmd.Hourglass True
' Skip error codes that generate application or object-defined errors.
If Err.Description <> conAppObjectError Then
rst.AddNew
rst!ErrorCode = Err.Number
rst!ErrorString = Err.Description
rst.Update
End If
Err.Clear
Next lngCode
rst.Close
DoCmd.Hourglass False
MsgBox "Errors table created."
Set rst = Nothing
Set dbs = Nothing
End Sub