Error message numbers

  • Thread starter Thread starter Gina Whipp
  • Start date Start date
G

Gina Whipp

Anyone....

A long time ago I found a way to print Access and Jet Error Messages with
their prespective numbers so I could set my own. I think it was a module
that I ran. Well, I can't figure out how I did it, does anyone have a clue?

As always thanks in advance!
Gina
 
The built-in function AccessError will return the text of the error
description if you pass it an error number (although it's a little cryptic,
as it contains placeholders where Access will fill in object names when the
real error occurs). Just create a loop that runs from, say, 1 to 3500:

For lngLoop = 1 To 3500
Debug.Print "Error # " & lngLoop & " = " & AccessError(lngLoop)
Next lngLoop
 
Okay, I found the code but it doesn't run in Access XP. I don't want to
print the error list I want to store it in a table. The below gives me a
runtime 13 where indicated and stops there. Can someone tell me what is
wrong? Thanks in advance... Gina

Sub CreateErrorsTable()
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) RUNTIME 13
tdf.Fields.Append fld
Set fld = tdf.CreateField("ErrorString", dbText, 255)
tdf.Fields.Append fld

dbs.TableDefs.Append tdf
' Open recordset on Errors table.
Set rst = dbs.OpenRecordset("Errors")
' Loop through first 1000 Visual Basic error codes.
For lngCode = 1 To 1000
On Error Resume Next
' Raise each error.
Err.Raise lngCode
DoCmd.Hourglass True
' Skip error codes that generate application or object-defined
errors.
If Err.Description <> conAppObjectError Then
' Add each error code and string to Errors table.
rst.AddNew

rst!ErrorCode = Err.Number
rst!ErrorString = Err.Description
rst.Update
End If
' Clear Err object.
Err.Clear
Next lngCode
' Close recordset.
rst.Close
DoCmd.Hourglass False
MsgBox "Errors table created."
End Sub
 
Back
Top