|
-
Mar 28th, 2000, 08:15 AM
#1
Thread Starter
Junior Member
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?
-
Jun 13th, 2001, 04:53 PM
#2
Junior Member
Me too
I am having the same problem. Did you find a fix?
-
Jun 15th, 2001, 03:22 PM
#3
Lively Member
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
-
Jun 15th, 2001, 03:28 PM
#4
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|