Results 1 to 6 of 6
  1. #1
    SaskiFX is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    30

    Using form to add record to Junction table

    So I have a Junction table that is combining a tblParts and and tblVendors that are combined into tblPrice. It uses "Part Number" and "Vendor ID" to join the tables. Each part can have multiple vendors with different prices.



    I have a form that is used to add new parts to the tblParts table, and I want to have a button that launches another from to add a Vendor as a supplier for a part. (All the vendors are already in the tblVendors table.) The second form comes up just fine, and I can get it to jump to a new record (using the OnLoad), but when it does that it clears all the fields. However, I want to keep one of the fields filled. When a user is hitting this button, the part number from tblParts field needs to stay the same, so when the user selects a vendor from my list, it generates a new unique record with the Part number and the Vendor ID.

    I have tried searching, and I can't seem to locate the correct settings or code to accomplish this.

    Help? Thanks!

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Consider a form/subform arrangement.

    Main form bound to tblParts and subform bound to tblPrice.

    Combobox on subform to select VendorID.

    No code required.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    SaskiFX is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    30
    Actually, that's the way I have it setup now. The main from is bound to tblParts, and the popup form is bound to tblPrice. I'm using a listbox instead of a combobox, but I wouldn't think that matters. But when I tell the pop-up form bound to tblPrice to generate a new record, it wipes out the "Part Number" field which I need to stay the same, since I'm just using the popup form to add a new vendor and part cost to the tblPrice table. I could have the user type it in again, or use another listbox, but it would make the interface unwieldy.

    Is there anyway to retrieve the "Part Number" value and hang onto it and automatically insert it in the new record? (In the end, I won't even have the Part Number field showing on the subform.)

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    A 'popup' form is not a subform. A subform sits on the main form. Related records are synchronized by the subform container control Master/Child links properties. The part number would automatically populate in the subform because of this link. This is the simplest approach for entering parent/child records. No code required.

    One way to 'carry forward' the part number to a new record is to set the DefaultValue property of the textbox in the textbox AfterUpdate event.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    SaskiFX is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Mar 2013
    Posts
    30
    Solved this by grabbing the Part Number key and storing it when launching the popup form, and restoring it when the popup loads.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    One way to pass a value to an opening form is with the OpenArgs argument of DoCmd.OpenForm. Then the opening form can have code in Current event to extract value from OpenArgs property.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Junction Table
    By troachjr in forum Database Design
    Replies: 1
    Last Post: 03-08-2013, 02:10 AM
  2. Junction Table ?
    By KCC47 in forum Access
    Replies: 1
    Last Post: 02-19-2013, 10:19 AM
  3. Updating junction table in form
    By Palladian in forum Forms
    Replies: 7
    Last Post: 11-14-2012, 12:27 AM
  4. Populating Junction table from form
    By JFo in forum Access
    Replies: 18
    Last Post: 09-05-2011, 09:15 PM
  5. Junction Table
    By mae3n in forum Database Design
    Replies: 2
    Last Post: 01-15-2011, 10:23 PM

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