Could you help me in building fnction for linking 2 tables? My tables are called TblOffers and TblOfferDetails.
To my regret it does not function and the error is :
"you cannot add or change a record because a related record is required in the "tbloffers"
My field Offerid in the TblOfers has a primary key and is autonumber.I have two primary keys in the TblOfferDetails : offerid and ProductID
The field OfferId in this table is Number.
M unhappy function is the following:
Private Function LinkTblOffersAndTblOfferDetails
Dim db As DAO.Database
Dim rel As DAO.Relation
Set db = CurrentDb
'On Error Resume Next
Do Until db.Relations.Count = 0
db.Relations.Delete db.Relations(0).Name
Loop
Set rel = db.CreateRelation("OfferIDRelationship", "tbloffers", "tblofferdetails", _
dbRelationUpdateCascade + dbRelationDeleteCascade)
rel.Fields.Append rel.CreateField("OfferID")
rel.Fields!offerid.ForeignName = "OfferID"
' Append relation
db.Relations.Append rel
db.Close
Set db = Nothing
End Function



