ACCESS VBA - DAO in VB - problem with creating relations
- by Justin
So take the following example:
Sub CreateRelation()
Dim db As Database
Dim rel As Relation
Dim fld As Field
Set db = CurrentDb
Set rel = db.CreateRelation("OrderID", "Orders", "Products")
'refrential integrity
rel.Attributes = dbRelationUpdateCascade
'specify the key in the referenced table
Set fld = rel.CreateField("OrderID")
fld.ForeignName = "OrderID"
rel.Fields.Append fld
db.Relations.Append rel
End Sub
I keep getting the error, No unique index found for the referenced field of the primary table.
if i include the vb before this sub to create in index on the field, it gives me the error: Index already exists.
so i am trying to figure this out. if there are not any primary keys set, will that cause this not to work? i am confused by this, but i really really want to figure this out. So orderID is a FOREIGN KEY in the Products Table
please help
thanks
justin