Sub ADOCreatePrimaryKey()
Dim cat As New ADOX.Catalog
Dim tbl As ADOX.Table
Dim pk As New ADOX.Key
cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\mydb.mdb;"
Set tbl = cat.Tables("Newtable")
pk.Name = "PrimaryKey"
pk.Type = adKeyPrimary
pk.Columns.Append "Column1"
tbl.Keys.Append pk
End Sub
|