ACC2000: How to Generate a list of Access Error Messages (268721)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q268721
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

SUMMARY

This article shows you how to programmatically create a list of Access error messages and to save the results to an Access table, complete with the associated error number.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
  1. Create a new Access database (.mdb).
  2. Create the following table:

    Table: tblErrorsAndDescriptions
    -------------------------------

    Field Name: ErrorNumber
    Data Type: Number
    Indexed: Yes (No Duplicates)
    Primary Key: Yes

    Field Name: ErrorDescription
    Data Type: Memo

  3. Save the table as tblErrorsAndDescriptions.
  4. Close the table.
  5. Create a new module.
  6. Type or paste the following code into the module:
    Option Compare Database
    
    Function sRecordAccessErrorMsg()
    
    Dim ADOcnn As ADODB.Connection
    Dim ADOrst As ADODB.Recordset
    
    Dim intCounter As Long
    Dim intErrornumber As Long
    Dim strErrorText As String
    
    Set ADOcnn = CurrentProject.Connection
    Set ADOrst = New ADODB.Recordset
    
    ADOrst.Open "tblErrorsAndDescriptions", ADOcnn, adOpenDynamic, adLockOptimistic
    
    With ADOrst
        For intCounter = 0 To 32767
            .AddNew
            !ErrorNumber = intCounter
            If IsNull(AccessError(intCounter)) Then
                !ErrorDescription = "No Error"
            ElseIf AccessError(intCounter) = "" Then
                !ErrorDescription = "No Error"
            Else
                !ErrorDescription = AccessError(intCounter)
            End If
            .Update
        Next intCounter
    End With
    
    MsgBox "Completed enumerating errors to the table."
    
    End Function
    
    					
  7. Save the module as Module1.
  8. Type the following line in the Immediate window, and then press ENTER:
    sRecordAccessErrorMsg
    					

Modification Type:MajorLast Reviewed:6/23/2005
Keywords:kbhowto KB268721