Error 2046

T

tom

I ran the following code to get the errors table:

Sub CreateErrorsTable()
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
' Open recordset on Errors table.
Set rst = dbs.OpenRecordset("Errors")
' Loop through first 1000 Visual Basic error codes.
For lngCode = 1 To 3000
On Error Resume Next
' Raise each error.
Err.Raise lngCode
DoCmd.Hourglass True
' Skip error codes that generate application or object-defined
errors.
If Err.Description <> conAppObjectError Then
' Add each error code and string to Errors table.
rst.AddNew

rst!ErrorCode = Err.Number
rst!ErrorString = Err.Description
rst.Update
End If
' Clear Err object.
Err.Clear
Next lngCode
' Close recordset.
rst.Close
DoCmd.Hourglass False
MsgBox "Errors table created."
End Sub

When I run this code 2046 comes up "Application-defined or object-defined
error" which is confusing since
after doing an internet search, this is a known access error. I am confused
on how access does error handling.
 
6

'69 Camaro

Hi, Tom.
When I run this code 2046 comes up "Application-defined or object-defined
error"

For code that works, please see the tip, "How to create a listing of the
Access and Jet errors," on the following Web page:

http://www.access.qbuilt.com/html/vba3.html

HTH.
Gunny

See http://www.QBuilt.com for all your database needs.
See http://www.Access.QBuilt.com for Microsoft Access tips and tutorials.
Blog: http://DataDevilDog.BlogSpot.com
http://www.Access.QBuilt.com/html/expert_contributors2.html for contact
info.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top