Joshua said:
I would like to find all error codes and their explanation in Access 2002.
For example when I write codes using ADO to read a data record from a
dataset, it may return a error code saying "record not found" or "duplicate
record" when add a new record .... etc. Applreciate some recommendation.
This is adapted almost verbatim from an Access 97 helpfile code example
which I could not find in Access 2002. I tried running it and it will work
fine if you have a reference set to DAO. Just drop it in a module and run it
from the Immediate window. It will create a table and fill it with all the
error codes for Access and Jet:
Option Compare Database
Option Explicit
Function AccessAndJetErrorsTable() As Boolean
Dim db As DAO.Database
Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim rst As DAO.Recordset
Dim 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 db = CurrentDb
Set tdf = db.CreateTableDef("tblErrorCodes")
Set fld = tdf.CreateField("ErrorCode", dbLong)
tdf.Fields.Append fld
Set fld = tdf.CreateField("ErrorString", dbMemo)
tdf.Fields.Append fld
db.TableDefs.Append tdf
' Open recordset on Errors table.
Set rst = db.OpenRecordset("tblErrorCodes")
' 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
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access