ADOX/Jet database column autoincrement assignment problem

M

Michael

I am trying to create an access database within Net 2003 using the ADOX
library which works fine except when I try to add the AutoIncrement property
to the ContactId column.

I am experiencing a Property 'item' is ReadOnly error within the below line

.Columns("ContactId").Properties("AutoIncrement") = True

Am I missing a reference or what am I doing wrong?????

Following is the sample code I am using (ex MSDN) as the starting point.

'Project references
'Microsoft ADO Ext. 2.8 for DDL and Security
'Microsoft ActiveX Data Accss Objects 2.8 Library


Imports ADOX
Imports ADOX.DataTypeEnum

Sub Main()

Dim cnn As New ADODB.Connection
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table

cnn.Open "Provider='Microsoft.Jet.OLEDB.4.0';" & _
"Data Source='Northwind.mdb';"
cat.ActiveConnection = cnn

With tbl
.Name = "MyContacts"
.ParentCatalog = cat
' Create fields and append them to the new Table object.
.Columns.Append "ContactId", adInteger
' Make the ContactId column and auto incrementing column
.Columns("ContactId").Properties("AutoIncrement") = True
.Columns.Append "CustomerID", adVarWChar
.Columns.Append "FirstName", adVarWChar
.Columns.Append "LastName", adVarWChar
.Columns.Append "Phone", adVarWChar, 20
.Columns.Append "Notes", adLongVarWChar
End With
cat.Tables.Append tbl
'Clean up
cnn.Close
Set cat = Nothing
Set tbl = Nothing
Set cnn = Nothing
End Sub
 
J

james

Try changing it to this:
..Columns("ContactId").Properties("AutoIncrement").Value = True

I had the same error until I did it this way.

james
 
M

Michael

James

The fix worked - thanks

Mike

james said:
Try changing it to this:
.Columns("ContactId").Properties("AutoIncrement").Value = True

I had the same error until I did it this way.

james
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top