Set column "Identity" property

G

Gerry G.

I am appending a new table in an Access Project. I am trying to set the
"Identity" property (autoincrement) of the first column in the table. I
receive the following error message:

"run time error 3265, Item cannot be found in the collection corresponding
to the requested name or ordinal.

My partial code is below:

Set cnxn = New ADODB.Connection
cnxn.Provider = "SQLOLEDB"
cnxn.Properties("Data Source").Value = "RADIANCE\PETROTEST"
cnxn.Properties("Initial Catalog").Value = "master"
cnxn.Properties("Integrated Security").Value = "SSPI"
cnxn.Open
Set cat1 = New ADOX.Catalog
Set cat1.ActiveConnection = cnxn

'Create and name the table

Set ImportTable = New ADOX.Table
With ImportTable
.Name = "zzDonors"
Set .ParentCatalog = cat1
With .Columns
.Append "Rec_Index", adInteger
.Item("Rec_Index").Properties("Identity(1,1)") = 0
.Append "Supplier", adVarWChar, 100
.Append "Terminal_Name", adVarWChar, 50
.Append "Terminal_Abbr", adVarWChar, 20
.Append "Terminal_City", adVarWChar, 50
.Append "Terminal_State", adVarWChar, 5
.Append "Product_Name", adVarWChar, 120
.Append "Brand_Type", adVarWChar, 5
.Append "Effective_Date", adDBTimeStamp
.Append "Effective_Time", adDBTimeStamp
.Append "Price", adSingle
.Append "Change", adSingle
End With
End With
'

'Append new table to Tables collection of Project
cat1.Tables.Append ImportTable


When I remove the following code the table is appended but of course the
"identity" property is not set:

.Item("Rec_Index").Properties("Identity(1,1)") = 0

Please, what is the correct code to set this property?

Thanks

Gerry
 
A

aaron.kempf

can't you just

Docmd.RunSQL "CREATE TABLE MYTABLENAME"

this is a lot more powerful and simple.. no?
 
V

Vadim Rapp

GG> With .Columns
GG> .Append "Rec_Index", adInteger
GG> .Item("Rec_Index").Properties("Identity(1,1)") = 0

should be

..Item("Rec_Index").Properties("autoincrement") = True


Vadim Rapp
 

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