Results 1 to 5 of 5
  1. #1
    Tree is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    2

    Many to many relationship forms

    I have a Physicians table (name, address, etc.) and a Hospitals table (similar fields) in a many to many relationship via a junction table containing the primary key from each of these tables. Each physician can work at multiple hospitals, and each hospital can have multiple physicians.



    I have built a form for entering new records for Physicians. I would like to include a subform in which the user can (1) select all the associated hospitals for that physician from a drop-down list of all hospitals in the hospital table, or (2) enter a new hospital name that creates a new hospital record.

    I have created a subform from the junction table that enables me to enter in the AutoNumber associated with a hospital record, but then the user has to know the hospital's AutoNumber, instead of simply selecting a hospital name from a list.

  2. #2
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    You can create a combo box where the BOUND column is the hospital ID, and the second column is the hospital name. When you display the combo box if you set the BOUND column (typically the first column) to 0 and the second column to something wider than 0, when the person does data entry they will only see the hospital name and they can type it in as normal but the value that is stored will be the hospital ID.

    Adding a new hospital if it does not exist in your list is a bit more complex normally I provide a button that would, for instance, say 'add hospital' it would open up a hospital editing screen to allow the user to put something in, then when the form closes I would force a refresh of the data and requery the combo box that contains the hospital names.

  3. #3
    Tree is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2011
    Posts
    2
    I understand your suggestion but do not know how to do it.

    The subform is connected to the junction table, where the HospitalID resides, but the Hospital name is in the Hospital table. How do I create a two-column combo box in the subform that is connected to both the junction table and the Hospital table?

  4. #4
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    .... When you display the combo box if you set the BOUND column (typically the first column) to 0 and the second column to something wider than 0, ........
    Shouldn't this be:
    ...When you display the combo box if you set the BOUND column (typically the first column) width to 0 and the second column width to something wider than 0,.....

  5. #5
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,442
    Can you post a sample database it'd be far easier to modify yours than write one from scratch. Just make sure there's no personal information in the database, then zip it and post it on this forum.

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

Similar Threads

  1. Replies: 5
    Last Post: 05-18-2011, 08:57 AM
  2. Replies: 1
    Last Post: 01-04-2011, 05:04 AM
  3. Replies: 4
    Last Post: 04-01-2009, 08:49 PM
  4. Relationship
    By pcandns in forum Access
    Replies: 2
    Last Post: 04-01-2009, 09:32 AM
  5. Many-to-Many Relationship
    By Carolyn1 in forum Database Design
    Replies: 0
    Last Post: 09-25-2006, 02:04 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