Article ID: 201826
Article Last Modified on 8/23/2001
Dim cnn As ADODB.Connection
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim col As ADOX.Column
Dim idx As ADOX.Index
Set cnn = CreateObject("ADODB.Connection")
With cnn
.ConnectionString = "PROVIDER=SQLOLEDB" & _
";DATA SOURCE=<server name>" & _
";USER ID=<uid>;PASSWORD=<pwd>" & _
";INITIAL CATALOG=<catalog name>"
.Open
End With
Set cat = CreateObject("ADOX.Catalog")
cat.ActiveConnection = cnn
Set tbl = CreateObject("ADOX.Table")
tbl.Name = "test"
tbl.Columns.Append "iMyID", adInteger
tbl.Columns.Append "cTest", adChar, 15
' Comment the Line below and
' Uncomment the duplicate line two lines below to avoid error.
tbl.Columns(0).Properties("Autoincrement").Value = True
'This line is the key.
Set tbl.ParentCatalog = cat
'tbl.Columns(0).Properties("Autoincrement").Value = True
cat.Tables.Append tbl
Some data providers allow provider-specific property values to be written only at creation (when a table or column is appended to its Catalog collection). To access these properties before appending these objects to a Catalog, specify the Catalog in the ParentCatalog property first.
Keywords: kbdatabase kbprb KB201826