PDA

Click to See Complete Forum and Search --> : I am tring to make an auto-increment field...


daamazing1
Mar 28th, 2000, 07:15 AM
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?

Gary Z
Jun 13th, 2001, 04:53 PM
I am having the same problem. Did you find a fix?

Rastro
Jun 15th, 2001, 03:22 PM
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/officedev/odeopg/deovrcreatingmodifyingaccesstables.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

Gary Z
Jun 15th, 2001, 03:28 PM
I changed from jet 3.51 to 4.0 and now I don't have the problem.
Thanks