Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2004
    Posts
    8

    Unanswered: Can you populate a Foreign key?

    Is there a way to populate a foreign key when a form is opened from the form that contains the primary key? I have an order form with a button that opens a production form. NewHouseId is the primary key in the Orders form and is autonumber.



    I would like the NewHouseId, foreign key to be populated when the Production form is opened from the Orders form. I tried putting =Forms![NewHouseF]![NewHouseId] in the control source of the Production form and it does enter the NewHouseId in the foreign key BUT when I try to close the form or go to the next record I get a message that says “You cannot add or change a record because a related record is required in table ‘OrdersT’”.



    What am I doing wrong or can this be done?

  2. #2
    Join Date
    Jan 2004
    Location
    Aberdeen, Scotland
    Posts
    1,067
    How about instead of putting

    =Forms![NewHouseF]![NewHouseId]
    into the control source qput it into the default value of your box

    Then put the name of your FK Field into Control Source if you lock the results then the user cant change them,

    HTH
    Dave

  3. #3
    Join Date
    Aug 2004
    Posts
    8
    Thank you Dave, that worked great!

Posting Permissions

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