Results 1 to 4 of 4

Thread: I am tring to make an auto-increment field...

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2000
    Posts
    17
    I am tring to make an auto-increment field but every time I do I get an error message saying that "Item can not be found in collection", I can add fields to tables but not the autoincrement. the code I'm using is:

    ADO_Table.Columns.Item("NameOfField").Properties _("AutoIncrement") = True

    In the watch window under the
    .columns.item ("NameOfField).properties.count = 0
    is this normal?

  2. #2
    Junior Member
    Join Date
    May 2001
    Location
    Wisconsin, USA
    Posts
    19

    Me too

    I am having the same problem. Did you find a fix?

  3. #3
    Lively Member
    Join Date
    Apr 2001
    Location
    New York
    Posts
    73
    I think the problem is you need to set the ParentCatalog first to a catalog with a valid connection, so ADO knows which provider you're using and whether they support AutoIncrement fields.

    Copied the code below from the following page which I look at any time I need to use ADOX.


    http://msdn.microsoft.com/library/of...cesstables.htm


    Sub CreateAutoNumberField(strDBPath As String)
    Dim catDB As ADOX.Catalog
    Dim tbl As ADOX.Table

    Set catDB = New ADOX.Catalog
    ' Open the catalog.
    catDB.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=" & strDBPath

    Set tbl = New ADOX.Table
    With tbl
    .Name = "Contacts"
    Set .ParentCatalog = catDB
    ' Create fields and append them to the
    ' Columns collection of the new Table object.
    With .Columns
    .Append "ContactId", adInteger
    ' Make the ContactId field auto-incrementing.
    .Item("ContactId").Properties("AutoIncrement") = True
    .Append "CustomerID", adVarWChar
    .Append "FirstName", adVarWChar
    .Append "LastName", adVarWChar
    .Append "Phone", adVarWChar, 20
    .Append "Notes", adLongVarWChar
    End With
    End With

    ' Add the new Table to the Tables collection of the database.
    catDB.Tables.Append tbl

    Set catDB = Nothing
    End Sub

  4. #4
    Junior Member
    Join Date
    May 2001
    Location
    Wisconsin, USA
    Posts
    19
    I changed from jet 3.51 to 4.0 and now I don't have the problem.
    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width