ACC2000: Unexpected Behavior Referencing Properties and Methods of an Object (223212)
The information in this article applies to:
This article was previously published under Q223212 Advanced: Requires expert coding, interoperability, and multiuser skills.
This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).
SYMPTOMS
When you run ActiveX Data Objects (ADO) code that references properties or methods of an object, you receive either unexpected results or the following error message:
Run-time error '3265':
ADO could not find the object in the collection corresponding to the name or ordinal reference requested by the application.
CAUSE
The object has not yet been added as a member of the collection.
RESOLUTION
Avoid referencing properties and methods of objects that have not yet been added to their collections.
For example, the "Sample of Unexpected Results" example in the "More Information" section of this article contains the following:
'Count the number of properties of the MyID field BEFORE adding
'MyNewTable to the tables collection.
lngCount = tbl.Columns("MyID").Properties.Count
'Display the number of properties found.
Debug.Print "Number of properties BEFORE: " & lngCount
'Add the new table to the collection.
cat.Tables.Append tbl
'Count the number of properties after adding MyNewTable to collection.
lngCount = tbl.Columns("MyID").Properties.Count
'Display the number of properties found.
Debug.Print " Number of Properties AFTER: " & lngCount
In this example, avoid unexpected results by not referencing the Count property prior to adding the table to the collection. In other words, remove the code:
'Count the number of properties of the MyID field BEFORE adding
'MyNewTable to the tables collection.
lngCount = tbl.Columns("MyID").Properties.Count
'Display the number of properties found.
Debug.Print "Number of properties BEFORE: " & lngCount
The "Sample of Unexpected Error" example in the "More Information" section of this article contains the following:
'Display the name of the first property for MyID.
Debug.Print tbl.Columns("MyID").Properties.Item(0).Name
'Add the new table to the Tables collection.
cat.Tables.Append tbl
Avoid the error message by not referencing the Name property prior to adding the table to the collection. In other words, remove the code:
'Display the name of the first property for MyID.
Debug.Print tbl.Columns("MyID").Properties.Item(0).Name
Modification Type: | Minor | Last Reviewed: | 10/11/2006 |
---|
Keywords: | kbprb kbProgramming KB223212 |
---|
|