Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error description in Immediate window

Status
Not open for further replies.

annie52

Technical User
Mar 13, 2009
164
US
It seems like I should be able to find the error description when I type the error number in the Immediate window but I can't figure out how to do that.

If I try:
?Err.Number(2451)
I'm told I have the wrong number of arguments or invalid property assignment. The Help file isn't very helpful.
 
try
On Error Resume Next
Err.Raise 11
Debug.Print Err.Description
 
Hi, pwise. That seems to work with runtime errors but not with application-defined or object-defined errors. Any other thoughts?
 
I still haven't figured this out. Does anyone else have any other ideas? Thanks.
 
You can't assign a value to the err object (2451). In the immediate window, Err.Number/Description returns the last error if there was one. Try an error handler. Here is a sample of one of mine:

Code:
On Error GoTo PRINT_REPORTS_ERR


'........ code

PRINT_REPORTS_EXIT:
    Exit Sub
  
PRINT_REPORTS_ERR:
    MsgBox "Print Reports " & vbCrLf & "Error Number: " & Err.Number _
           & vbCrLf & Err.Description, vbCritical
    Resume PRINT_REPORTS_EXIT


If you are using RaiseError, use IF...THEN to test for the error you raised, ELSE Resume Next.


Cogito eggo sum – I think, therefore I am a waffle.
 
Hi genomon. I do use error handlers. What I'm trying to do here is a generic task of finding the decription of any error number I may want to look up.
 
How about just enumerating them into a table for lookup?
Code:
Sub CreateErrorsTable()

'The following procedure creates a table in Microsoft Access containing the error codes
'and strings used or reserved by Visual Basic. The table doesn't include Data Access
'Objects (DAO) errors.
'Visual Basic reserves a portion of the first thousand possible error numbers, so this
'example considers only error numbers between 1 and 1000. Other error numbers are
'reserved by the Microsoft Jet database engine, or are available for defining custom errors.

    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)
    tdf.Fields.Append fld
    Set fld = tdf.CreateField("ErrorString", dbText, 255)
    tdf.Fields.Append fld
    dbs.TableDefs.Append tdf
    Set rst = dbs.OpenRecordset("Errors")
    For lngCode = 1 To 1000  ' Loop through first 1000 Visual Basic error codes.
        On Error Resume Next
        Err.Raise lngCode   'Raise each error.
        DoCmd.Hourglass True
        ' Skip error codes that generate application or object-defined errors.
        If Err.Description <> conAppObjectError Then
            rst.AddNew
            rst!ErrorCode = Err.Number
            rst!ErrorString = Err.Description
            rst.Update
        End If
        Err.Clear
    Next lngCode
    rst.Close
    DoCmd.Hourglass False
    MsgBox "Errors table created."
    Set rst = Nothing
    Set dbs = Nothing
    
End Sub

Cogito eggo sum – I think, therefore I am a waffle.
 
If Err.Description <> conAppObjectError Then[/color red]

Actually, these are the errors I was interested in. I already had a handle on run-time errors.
 
Then comment out the IF and END IF.

Cogito eggo sum – I think, therefore I am a waffle.
 
Wasn't thinking right - just change the <> to =.
If Err.Description = conAppObjectError Then

Cogito eggo sum – I think, therefore I am a waffle.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top