I am trying to add a new table with a primary key and want to set its AutoIncrement property to True. That's what I'm doing:
Dim cat As New ADOX.Catalog
Dim tbl As New ADOX.Table
Dim col As New ADOX.Column
Dim cnn As Object
Dim dbs As Database
Dim DataSource As String
DataSource = "\\spdb\depts\Msg_be.accdb"
Set cnn = CreateObject("ADODB.Connection")
cnn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=" & DataSource & ";Jet OLEDB:Database Password=psWrD; "
Set dbs = OpenDatabase(DataSource, False, False, "MS Access;PWD=psWrD")
cat.ActiveConnection = cnn
tbl.Name = "tblMsg"
tbl.Columns.Append "MsgID", adInteger
tbl.Keys.Append "PrimaryKey", adKeyPrimary, "MsgID"
tbl.Columns.Item("MsgID").Properties("AutoIncrement") = True
cat.Tables.Append tbl
However, I get this error:
Run-time error '3265':
Item cannot be found in the collection corresponding to the requested name or ordinal.
in line:
tbl.Columns.Item("MsgID").Properties("AutoIncrement") = True
Did I miss something?
source
share