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
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