Results 1 to 11 of 11
  1. #1
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393

    Adding same values to multiple tables at once

    Quite a general question here for any forms... what is the best way to add a record to two tables at the same time?

    Say for example you had a tblLocation table that had a foreign key that is CityID... what is best way to add a city and therefore add the CityID to both the tblLocation and tblCity at the same time using one form (lets call it frmLocation) just by clicking a single command button?

  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
    So during data entry you discover the city is not in a combobox list and want to add the new city record and also finish the data entry record? Check out the combobox NotInList property: http://www.fontstuff.com/access/acctut20.htm
    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
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    yes this looks to be one of the things I was looking for, I will try and have a play with the code from the examples and see if I can get it to do what I want it to do

    Thanks

  4. #4
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    Ok that is great for combos and not really what I was after but works a treat and I will be using it for sure

    what I need though is say you have a many to many relationship lets say a relationship like

    Inspections <--> Equipment

    where
    1 inspection can have many pieces of equipment
    and
    1 piece of equipment can be in many inspections

    Therefore you need a junction table when entering each piece of equipment for any given inspection.

    The way I have designed this so far is to start an inspection on a form that has a command button that adds another piece of equipment to the inspection by equipment type therefore I need the Inspection ID and the Equipment ID to not only add to their respective tables but also need them to add to the junction table for each piece of equipment

    Let me know if you need any more info

    Thanks

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Not sure I understand. If tables are properly related and form structured correctly, no need for code to add records, unless it is a new piece of equipment not already in the equipment source table and that's where the combobox NotInList event plays a role. You need to use form/subform arrangement. Main form bound to the inspection table and subform bound to the junction table where you will select equipment related to the inspection. The subform container control will synchronize records of the two forms with Master/Child link properties. No button to add equipment to the junction table is needed.
    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.

  6. #6
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    Thanks June7 I don't think I am explaining myself properly. The not in list property is great and I will be using it for different areas including equipment type you are correct.

    What I am trying to do is when I start entering data for a new inspection I will select from the equipment list this part is fine and not in list can be used here. So already I have the InspectionID which goes into inspection table. I then choose to add a piece of equipment to the inspection. Therefore I select the equipment type from the drop down list and so the EquipmentTypeID must also go into the Equipment table and the new EquipmentID must also go into the new equipment table as this is a different piece of equipment even though it is the same type. This is all OK however I need a way to link the inspection to the Equipment and due to the many to many relationship I need to enter the EquipmentID and the InspectionID in the junction table

    This will need to be completed for every piece of equipment in the inspection, furthermore the different pieces of equipment may be involved in other inspections as well

    Thanks

  7. #7
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    So I need a way to generate the new InspectionID and EquipmentID for a new inspection and piece of equipment in their respective tables and insert them into the EquipmentInspectionJunction table for each piece of equipment per inspection

  8. #8
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    Are the ID's autonumber datatype? My previous comments unchanged. Use form/subform with Master/Child linking.
    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.

  9. #9
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    Yes they are Autonumber...

    I think I follow that logic I could have a hidden subform with the junction values and pass from main form to subform and make mainform bound to Equipment table and subform bound to junction table. Is this right?

    thanks

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,624
    The subform would not be hidden, it would be where you enter records relating equipment to inspection in the junction table.

    Main form bound to Inspection table, subform bound to junction table, Master/Child link on Inspection keys, combobox on subform to select equipment. Linking on the Inspection keys will cause Inspection foreign key in junction table to populate as soon as an equipment is selected. Build it. Try it.
    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.

  11. #11
    JFo is offline Competent Performer
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Posts
    393
    OK I will try, thanks

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

Similar Threads

  1. Replies: 2
    Last Post: 05-19-2011, 06:15 AM
  2. Adding duplicate values in a query
    By mooseisloose in forum Queries
    Replies: 3
    Last Post: 04-14-2011, 12:12 PM
  3. Adding values to another field
    By GraemeG in forum Queries
    Replies: 0
    Last Post: 04-07-2011, 09:56 AM
  4. Replies: 3
    Last Post: 03-16-2011, 12:44 PM
  5. Replies: 8
    Last Post: 05-25-2010, 04:50 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