Primary Key in access

  • Thread starter Thread starter Lars Grøtteland
  • Start date Start date
L

Lars Grøtteland

Hello!

I'm trying to add Primary keys from adox code - but in the access file, it
doesn't show - even the return value from adox is true. The access file is
in 1997

Am I missing something here?
 
Lars, I found this sample code that sets up a foreign Key.


Dim kyForeign As New ADOX.Key
Dim cat As New ADOX.Catalog

cat.ActiveConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data
Source=c:\Program Files\MicrosoftOffice\Samples\Northwind.mdb;"

' Define the foreign key
kyForeign.Name = "CustOrder"
kyForeign.Type = adKeyForeign
kyForeign.RelatedTable = "Customers"
kyForeign.Columns.Append "CustomerId"
kyForeign.Columns("CustomerId").RelatedColumn = "CustomerId"
kyForeign.UpdateRule = adRICascade

' Append the foreign key
cat.Tables("Orders").Keys.Append kyForeign

'Delete the Key as this is a demonstration
cat.Tables("Orders").Keys.Delete kyForeign.Name

Looking further into Help I found the following constants defined

Constant Value Description
adKeyPrimary 1 Default. The key is a primary key.
adKeyForeign 2 The key is a foreign key.
adKeyUnique 3 The key is unique.


I've not tried this, but it might be a good place to start. Alternatively,
do you have some sample code?
 
Back
Top