469,613 Members | 1,195 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

ADOX/Jet database column autoincrement assignment problem

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

Nov 21 '05 #1
6 8867
Try changing it to this:
..Columns("ContactId").Properties("AutoIncrement") .Value = True

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

james


"Michael" <mc********@houston.rr.com> wrote in message news:Pr*****************@fe2.texas.rr.com...
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

Nov 21 '05 #2
Try changing it to this:
..Columns("ContactId").Properties("AutoIncrement") .Value = True

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

james


"Michael" <mc********@houston.rr.com> wrote in message news:Pr*****************@fe2.texas.rr.com...
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

Nov 21 '05 #3
James

The fix worked - thanks

Mike

"james" <jjames700ReMoVeMe at earthlink dot net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Try changing it to this:
.Columns("ContactId").Properties("AutoIncrement"). Value = True

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

james


"Michael" <mc********@houston.rr.com> wrote in message
news:Pr*****************@fe2.texas.rr.com...
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


Nov 21 '05 #4
James

The fix worked - thanks

Mike

"james" <jjames700ReMoVeMe at earthlink dot net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Try changing it to this:
.Columns("ContactId").Properties("AutoIncrement"). Value = True

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

james


"Michael" <mc********@houston.rr.com> wrote in message
news:Pr*****************@fe2.texas.rr.com...
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


Nov 21 '05 #5
Glad it worked for you.
james

"Michael" <mc********@houston.rr.com> wrote in message news:ue******************@fe2.texas.rr.com...
James

The fix worked - thanks

Mike

"james" <jjames700ReMoVeMe at earthlink dot net> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl...
Try changing it to this:
.Columns("ContactId").Properties("AutoIncrement"). Value = True

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

james

Nov 21 '05 #6
Glad it worked for you.
james

"Michael" <mc********@houston.rr.com> wrote in message news:ue******************@fe2.texas.rr.com...
James

The fix worked - thanks

Mike

"james" <jjames700ReMoVeMe at earthlink dot net> wrote in message news:%2****************@TK2MSFTNGP14.phx.gbl...
Try changing it to this:
.Columns("ContactId").Properties("AutoIncrement"). Value = True

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

james

Nov 21 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Tamblyne | last post: by
1 post views Thread by momo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.