BUG: Attributes Property of ADOX Columns Collection May Cause Append Method to Fail (272001)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 1.5
  • ActiveX Data Objects (ADO) 2.0
  • ActiveX Data Objects (ADO) 2.1
  • ActiveX Data Objects (ADO) 2.5
  • ActiveX Data Objects (ADO) 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

  1. Create a Standard EXE project in Microsoft Visual Basic. Form1 is created by default.
  2. 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
  3. 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 = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
                  "data source=c:\db1.mdb;user id=admin;password=;"
      conn.Open
      cat.ActiveConnection = conn
      Set tbl.ParentCatalog = cat
    
      tbl.Name = "ADOXTab"
      col = "Col1"
      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("Default") = 10
      cat.Tables.Append tbl
    

REFERENCES

For additional information on the limitations of ADOX, click the article numbers below to view the articles in the Microsoft Knowledge Base:

198534 ADOX Readme File Included with ADO 2.1 Components

271483 Design features of ADOX


Modification Type:MajorLast Reviewed:10/16/2002
Keywords:kbBug kbCodeSnippet kbDatabase kbDSupport KB272001