Microsoft KB Archive/272001

= BUG: Attributes Property of ADOX Columns Collection May Cause Append Method to Fail =

Article ID: 272001

Article Last Modified on 10/16/2002

-

APPLIES TO


 * Microsoft ActiveX Data Objects 1.5
 * Microsoft ActiveX Data Objects 2.0
 * Microsoft ActiveX Data Objects 2.1
 * Microsoft ActiveX Data Objects 2.5
 * Microsoft ActiveX Data Objects 2.6

-



This article was previously published under Q272001



SYMPTOMS
Attempting to set the Attributes property of a Microsoft ActiveX Data Object (ADOX) Column object to anything other than 0 may cause the Append method of the Tables collection to fail with the following error message:

Run-time error '3265':

Item cannot be found in the collection corresponding to the requested name or ordinal.



CAUSE
This is caused by a bug in the Microsoft ActiveX Data Objects Extensions for Data Definition Language (DDL) and Security, which prevents the setting of the Attributes property of a Column to anything but 0 (where a value of 0 means neither adColFixed nor adColNullable, the two possible values for this property) when other properties of the Column object are also set.



RESOLUTION
If you need to create a nullable or fixed length column, you must create the table through some mechanism other than ADOX, such as DDL SQL statements (CREATE TABLE, for example).



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



MORE INFORMATION
The error messages occurs only when you attempt to set one or more properties on a Column object and then also try to set the Attributes property to either adColFixed (1) or adColNullable (2).

Steps to Reproduce Behavior
 Create a Standard EXE project in Microsoft Visual Basic. Form1 is created by default. Set a Project reference to each of the following:  Microsoft ADO Ext. 2.x for DDL and Security

 Microsoft ActiveX Data Objects 2.x Library </li>  Paste the following code into the default Load method of the form: Dim conn As New ADODB.Connection Dim cat As New ADOX.Catalog Dim tbl As New ADOX.Table Dim col As String 'The following two lines make a connection to an Access database. 'Please change the .mdb path as needed. conn.ConnectionString = &quot;Provider=Microsoft.Jet.OLEDB.4.0;&quot; & _ &quot;data source=c:\db1.mdb;user id=admin;password=;&quot; conn.Open cat.ActiveConnection = conn Set tbl.ParentCatalog = cat

tbl.Name = &quot;ADOXTab&quot; col = &quot;Col1&quot; tbl.Columns.Append col, adInteger

tbl.Columns(col).Attributes = adColNullable Or adColFixed 'Comment out the preceding line and uncomment the next line to make 'the Append method work. 'tbl.Columns(col).Attributes = 0

tbl.Columns(col).Properties(&quot;Default&quot;) = 10 cat.Tables.Append tbl </li></ol>

<div class="references_section">