none
Get complete list of Access error codes and descriptions RRS feed

  • Question

  • Hi,

    I want to get a complete list of Access error codes and descriptions. So I follow the instructions at https://support.microsoft.com/en-us/kb/105666

    But the results are only errors from 3 to 746. All other error code will return one of the following 3 strings:

    1. "User-defined Error"

    2. "Reserved Error"

    3. "Application-defined or object-defined error"

    But I know there are many more errors, such as error 3343, why I cannot obtain the error string for such error code?

    Thanks


    Friday, September 9, 2016 7:27 AM

Answers

  • To get the Access-specific error text, use AccessError instead of Error:

    Sub ListErrors()
      Dim dbs As DAO.Database
      Dim rst As DAO.Recordset
      Dim i As Long
      Dim strErr As String
      Set dbs = CurrentDb
      Set rst = dbs.OpenRecordset("Error Codes", dbOpenDynaset)
      For i = 1 To 65535
        strErr = AccessError(i)
        If strErr <> "" And strErr <> "Application-defined or object-defined error" Then
          rst.AddNew
          rst!Err = i
          rst!Error = Left(strErr, 255)
          rst.Update
        End If
      Next i
      rst.Close
      Set rst = Nothing
      Set dbs = Nothing
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by chcw Saturday, September 10, 2016 8:56 AM
    Friday, September 9, 2016 11:28 AM

All replies

  • To get the Access-specific error text, use AccessError instead of Error:

    Sub ListErrors()
      Dim dbs As DAO.Database
      Dim rst As DAO.Recordset
      Dim i As Long
      Dim strErr As String
      Set dbs = CurrentDb
      Set rst = dbs.OpenRecordset("Error Codes", dbOpenDynaset)
      For i = 1 To 65535
        strErr = AccessError(i)
        If strErr <> "" And strErr <> "Application-defined or object-defined error" Then
          rst.AddNew
          rst!Err = i
          rst!Error = Left(strErr, 255)
          rst.Update
        End If
      Next i
      rst.Close
      Set rst = Nothing
      Set dbs = Nothing
    End Sub


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by chcw Saturday, September 10, 2016 8:56 AM
    Friday, September 9, 2016 11:28 AM
  • Also, you could take a look here. Hope it helps...
    Friday, September 9, 2016 2:31 PM
  • Hi, Hans,

    Thank you very much. That works perfectly!

    Saturday, September 10, 2016 8:56 AM
  • You can also look into dbdaoerr.h file that contains DAO specific error codes with comments: https://searchcode.com/codesearch/view/13884978/
    Saturday, September 10, 2016 9:06 AM
  • Hi, Hans,

    Is there a similar function ExcelError and WordError for Excel or Word as well?

    Thank you

    Saturday, September 10, 2016 10:25 PM
  • No, there isn't, but Word VBA and Excel VBA have fewer application-specific error messages than Access.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Saturday, September 10, 2016 11:23 PM
  • Hi, Hans,

    Thanks. In that case, is there any other way to obtain the Word and Excel errors? For example, find from a xxx.h file, like dbdaoerr.h for Access? Or is there official document from MS talking about this?

    Sunday, September 11, 2016 1:07 AM
  • I haven't found either, sorry.

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Sunday, September 11, 2016 8:18 AM
  • Hi Hans

    Sorry - I'm a couple of years late to this party

    Just found this excellent routine for creating the list of Access errors. 

    I then compared it with the list I obtained from MS a few years ago and which can also be found at the FMS website: http://www.fmsinc.com/MicrosoftAccess/Errors/ErrorNumber_Description2010.html

    Although both lists are almost identical, your list omits several important & very common errors

    Query2
    ErrorNumber ErrorDescription
    3 Return without GoSub
    20 Resume without error
    35 Sub or Function not defined
    91 Object variable or With block variable not set
    92 For loop not initialized
    94 Invalid use of Null

    It also adds several rather peculiar entries which I've never seen listed elsewhere

    Query1
    Err Error
    3004 **********
    3072 |
    3193 (unknown)
    3194 (unknown)
    3209 **********
    3316 |
    3369 **********
    3392 **********
    3395 **********
    3416 |
    3939 |1
    4000 |
    8057 |
    31665 |
    31671 |
    32619 0,0

    Any idea why these discrepancies occur?

    Apologies for the formatting above - it looked fine in preview mode - hopefully still understandable!



    • Edited by isladogs52 Sunday, June 3, 2018 10:18 AM
    Saturday, June 2, 2018 7:22 PM
  • The code that I posted merely lists what the AccessError returns. AccessError(3) is an empty string instead of "Return without GoSub", so the code skips it.

    The ones with error numbers above 3000 are idiosyncracies of Access. Apparently the developers created some text for those numbers, but I don't know if they are ever used, and if so, what for...


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Sunday, June 3, 2018 7:15 AM
  • Thanks for the speedy reply Hans

    I had already tested by removing the If line in your code & as you say error 3 line was blank

    And yet, of course, err.Raise 3 will give Return without GoSub.

    Similarly for errors 20, 35, 91, 92, 94. 

    Sunday, June 3, 2018 8:38 AM
  • You'll find a list of generic VBA errors at https://msdn.microsoft.com/en-us/vba/language-reference-vba/articles/trappable-errors

    This list does include error numbers 3, 20 etc.


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Sunday, June 3, 2018 8:46 AM
  • Yes I know - that was my whole point. 

    The 5 error codes I listed are Access error codes but are omitted using your clever function.

    Alternately if you use: strErr=Error(i) it includes all of those codes but of course stops at 746 therefore missing out a huge number of Access errors with higher numbers

    So what I'm suggesting would be a combination of both to get all valid error codes and omitting the 'spurious' codes in the second list I gave above

    Here is a working version that gets all 2976 error codes ONLY:

    Sub ListErrors()
    
    On Error GoTo Err_Handler
    
            Dim dbs As DAO.Database
            Dim rst As DAO.Recordset
            Dim i As Long, N As Long
            Dim strErr As String
            Set dbs = CurrentDb
            Set rst = dbs.OpenRecordset("ErrorCodes", dbOpenDynaset)
            
            For i = 1 To 65535
                  strErr = Error(i)
                  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!Err = i
                  '  rst!Error = Left(strErr, 255)
                    rst!Error = strErr
                    rst.Update
                  End If
            Next i
            
            For i = 1 To 65535
             'now repeat for Access errors
                  strErr = AccessError(i)
                  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!Err = i
                    'rst!Error = Left(strErr, 255)
                    rst!Error = strErr
                    rst.Update
                  End If
            Next i
              
            N = rst.RecordCount
            rst.Close
            Set rst = Nothing
            Set dbs = Nothing
            
            MsgBox "All " & N & " Access errors have been added to the table ErrorCodes", 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


    This is a bit clunky & could be tidied up but it does work.

    NOTE:

    Quite a few of the error descriptions are more than 255 characters.

    So I changed the Error (description) field to Memo / Long Text and changed the line rst!Error=Left(strErr,255) to rst!Error=strErr

    Hope this helps





    • Edited by isladogs52 Sunday, June 3, 2018 9:46 AM
    Sunday, June 3, 2018 9:10 AM
  • Thank you!

    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    Sunday, June 3, 2018 1:28 PM
  • You're welcome.

    Strange that it's necessary to do both generic and Access specific errors to get the full list.

    Also that such common errors would be missing from the Access list.

    Sunday, June 3, 2018 4:25 PM