Results 1 to 2 of 2
  1. #1
    4 Star Lounger
    Join Date
    Feb 2002
    Posts
    537
    Thanks
    0
    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
    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

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •