Connecting Tech Pros Worldwide Help | Site Map

Error in setting multiple field relationships with vba

Andrew W
Guest
 
Posts: n/a
#1: Feb 16 '06
I am trying to set up a relationship between three fields that make the
primary key of two tables. I am able to do this thru the Access
Relationships utility, but not thru VBA. I get the message: 'No unique
index found for the referenced field of the primary table". I've
checked the dataype and length of each of the three text fields that
make the primary key. It seems like Access is trying to make one part
of the relationship at a time. Any help will be appreciated.

Set db = OpenDatabase("g:\dataexport_2162006.mdb")

Set Rel = db.CreateRelation("Rel1")

With Rel
.Table = "tblSiteVisit"
.ForeignTable = "tblFieldSystems1"
'.Attributes = dbRelationUpdateCascade +
dbRelationDeleteCascade

'Set up the fields of the relation
Set Fld = .CreateField("site")
Fld.ForeignName = "site"
.Fields.Append Fld
End With

Set Rel = db.CreateRelation("Rel2")
With Rel
.Table = "tblSiteVisit"
.ForeignTable = "tblFieldSystems1"
'.Attributes = dbRelationUpdateCascade +
dbRelationDeleteCascade

'Set up the fields of the relation
Set Fld = .CreateField("technician")
Fld.ForeignName = "technician"
.Fields.Append Fld
End With

Set Rel = db.CreateRelation("Rel3")
With Rel
.Table = "tblSiteVisit"
.ForeignTable = "tblFieldSystems1"
'.Attributes = dbRelationUpdateCascade +
dbRelationDeleteCascade

'Set up the fields of the relation
Set Fld = .CreateField("sitevisitdate")
Fld.ForeignName = "sitevisitdate"
.Fields.Append Fld
End With
'Append the relation

db.Relations.Append Rel

Closed Thread