Go Back   Access World Forums > Microsoft Access Reference > Code Repository

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 06-03-2018, 02:37 PM   #1
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 7,888
Thanks: 98
Thanked 1,963 Times in 1,827 Posts
isladogs is a glorious beacon of light isladogs is a glorious beacon of light isladogs is a glorious beacon of light isladogs is a glorious beacon of light isladogs is a glorious beacon of light
Create a list of all Access error codes

The procedure below creates a table AccessErrorCodes and populates it with all 2976 errors (codes & descriptions) as used by Access 2010.
If you use it in A2016, it lists 3063 errors

The other 2 procedures CheckTableExists and MakeErrorCodesTable are used in this procedure.

Place all of these in a standard module and run the ListErrors procedure

Code:
Option Compare Database
Option Explicit

Sub ListErrors()

'Purpose : Populate an AccessErrorCodes table with all 2976 current Access error codes and descriptions
'Author(s) : Colin Riddington - adapted from code originally by Hans Vogelaar
'Date : 3 June 2018

'Requires: table ErrorCodes with 2 fields ErrNumber (PK - integer) & ErrDescription (Memo/LongText)
'If table doesn't exist, it will be created

On Error GoTo Err_Handler

        Dim rst As DAO.Recordset
        Dim i As Long, N As Long
        Dim strErr As String
        
        'make table if it doesn't exist
        If CheckTableExists("AccessErrorCodes") = False Then MakeErrorCodesTable
               
        Set rst = CurrentDb.OpenRecordset("AccessErrorCodes", dbOpenDynaset)
        
        For i = 1 To 65535
             'get generic VBA errors
              strErr = Error(i)
              'omit unwanted codes
              If strErr <> "" And strErr <> "Application-defined or object-defined error" Then
                '  And strErr <> "|" And strErr <> "|1" And strErr <> "**********" _
               '   And strErr <> "0,0" And strErr <> "(unknown)") Then
                rst.AddNew
                rst!ErrNumber = i
                rst!ErrDescription = strErr
                rst.Update
              End If
        Next i
        
        For i = 1 To 65535
         'now repeat for Access specific errors
              strErr = AccessError(i)
              'omit all unwanted codes
              If strErr <> "" And strErr <> "Application-defined or object-defined error" _
                  And strErr <> "|" And strErr <> "|1" And strErr <> "**********" _
                  And strErr <> "0,0" And strErr <> "(unknown)" Then
                rst.AddNew
                rst!ErrNumber = i
                rst!ErrDescription = strErr
                rst.Update
              End If
        Next i
          
        N = rst.RecordCount
        rst.Close
        Set rst = Nothing
        
        MsgBox "All " & N & " Access errors have been added to the table AccessErrorCodes", vbInformation, "Completed"
        
Exit_Handler:
    Exit Sub
    
Err_Handler:
    If Err = 3022 Then Resume Next 'continue where code already exists
    MsgBox "Error " & Err & " : " & Err.description & " in ListErrors procedure"
End Sub

'=============================

Public Function CheckTableExists(TableName As String) As Boolean
     
On Error Resume Next

'If table exists already then strTableName will be > ""
    Dim strTableName As String
    strTableName = CurrentDb.TableDefs(TableName).Name
    CheckTableExists = Not (strTableName = "")
    'Debug.Print strTableName & ": " & CheckTableExists
    
    'next 2 lines added to allow more than 1 table to be checked successfully
    strTableName = ""
    TableName = ""
    
End Function

'=============================

Sub MakeErrorCodesTable()

On Error GoTo Err_Handler

 'create new table
            Dim tdf As DAO.TableDef
            Dim fld As DAO.Field
            Dim InD As DAO.index
           
            Set tdf = CurrentDb.CreateTableDef("AccessErrorCodes")
        
            'Specify the fields.
            With tdf
                Set fld = .CreateField("ErrNumber", dbLong)
                fld.Required = True
                .Fields.Append fld
                
                Set fld = .CreateField("ErrDescription", dbMemo)
                fld.Required = True
                .Fields.Append fld
            End With
            
            'create primary key
            Set InD = tdf.CreateIndex("PrimaryKey")
            With InD
                .Fields.Append .CreateField("ErrNumber")
                .Unique = False
                .Primary = True
            End With
            tdf.Indexes.Append InD
            
             'Save the table.
            CurrentDb.TableDefs.Append tdf
            Set fld = Nothing
            Set tdf = Nothing
            Set InD = Nothing
            
Exit_Handler:
    Exit Sub
    
Err_Handler:
    MsgBox "Error " & Err & " : " & Err.description & " in MakeErrorCodesTable procedure"

End Sub
NOTE: This was based on code originally by Hans Vogelaar which I adapted to obtain various missing error codes. See https://social.msdn.microsoft.com/Fo...orum=accessdev

This created the same error codes as those used in the Access Error Codes example database (originally taken from an MS webpage which no longer exists)

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by isladogs; 06-06-2018 at 03:34 PM. Reason: Extra info
isladogs is offline   Reply With Quote
The Following User Says Thank You to isladogs For This Useful Post:
sonic8 (06-27-2018)
Reply

Tags
access error code list

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Access Error Codes isladogs Sample Databases 4 07-24-2017 07:16 AM
Access VBA Crashes, No Error Codes sirhannick Modules & VBA 11 05-06-2015 09:33 AM
Input Mask - codes to create custom listed Rx_ Forms 2 10-29-2010 08:43 AM
Access error codes GaelicFatboy General 3 01-24-2008 05:55 AM
Matching part of a variable with a list of codes Brian Martin Modules & VBA 5 12-15-2002 05:49 PM




All times are GMT -8. The time now is 08:22 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World