Results 1 to 2 of 2
2005-02-13, 11:03 #1
- Join Date
- Feb 2002
- Thanked 0 Times in 0 Posts
Building relationship (Access 2000)
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
Set rel = db.CreateRelation("OfferIDRelationship", "tbloffers", "tblofferdetails", _
dbRelationUpdateCascade + dbRelationDeleteCascade)
rel.Fields!offerid.ForeignName = "OfferID"
' Append relation
Set db = Nothing
2005-02-13, 11:09 #2
- Join Date
- Mar 2002
- Thanked 28 Times in 28 Posts
Re: Building relationship (Access 2000)
The error message means that there is a problem with your tables, not with the code itself. Apparently, tblOfferDetails contains one or more records with an OfferID that does not occur in tblOffers. Perhaps you have records in tblOfferDetails with OfferID = 0. You can find out which records cause problems by using the Find Unmatched Query Wizard to create a query that displays all records in tblOfferDetails without a matching value for OfferID in tblOffers.