Results 1 to 3 of 3
  1. #1
    Alico is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    5

    Avoid multiple entry for foreign key


    Hi All,

    I have a master to child table relation which is one to many. Each one is represented by a different form.

    The problem is, the user enters the primary key "JobID" on the master form, then he needs to enter a few records on the child list with the same "JobID" which is the foreign key in that case. I don't want the user to enter the "JobID" every time he enters a new record in the child form.

    Is there a way I can copy the primary key to the foreign key each time the user enters a new record in the child form?

    Thanks for your help & time.

    Regards,
    Ali

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Ideally, the user would not even be aware of a PK or FK. Computers manage these fields. You may find it easiest to use the Relationships Window in Access to define relationships for your tables. Once a relationship is defined, you can add constraints like Referential Integrity, Cascade Delete, Cascade Update, etc.

    My preference is to manage constraints using VBA. So I would just have code pass the value to the child table when the user triggers an event.

  3. #3
    hansendl is offline Advanced Hobbyist
    Windows 7 64bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    38
    I take it you're not using a subform? If you create a subform for your child records on your main form, and link the two using the LinkChildFields andLinkMasterFields properties, it will do what you're asking. When these properties are set, Access automatically updates the related record in the subform when you change to a new record in a main form. There are lots of resources on the web that explain how to do this, but here's one from the Microsoft Office development site: http://office.microsoft.com/en-us/ac...010098674.aspx.

    Good luck!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. avoid multiple queries
    By slimjen in forum Queries
    Replies: 4
    Last Post: 06-29-2014, 08:49 PM
  2. How do I avoid multiple entries
    By schwabe in forum Queries
    Replies: 2
    Last Post: 02-01-2012, 04:16 PM
  3. Multiple Foreign Help
    By Dalagrath in forum Access
    Replies: 2
    Last Post: 11-01-2010, 10:25 AM
  4. Multiple foreign key in table
    By pmstirling in forum Database Design
    Replies: 10
    Last Post: 02-23-2010, 04:00 PM
  5. Selecting foreign key values on data entry
    By hardya in forum Access
    Replies: 4
    Last Post: 02-11-2010, 11:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums