Results 1 to 12 of 12
  1. #1
    jlt199 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    34

    Linking multiple tables to one


    Hi, I have a database with three different groups of people: Physicians, Patients and Facilitators. I have a table for each. However, it's possible that any of these people can have multiple phone numbers. So I've created a Table (PhoneID | PersonID | PhoneNumber) where personID is either PhysicianID, PatientID or FacilitatorID - i.e. one table holds all the phone numbers.

    The ID for Physicians, Patients and Facilitators are all generated using autonumber. I had though that by changing the format of PatientID to "Pt"0 I could give the IDs from each table a unique prefix, ensuring that all PersonIDs are unique to a single person. But that isn't doing what I thought it was. It only changes the display, not the actual field. Please can someone suggest a method of making sure PersonID can relate to one person out of the combined Physicians, Patients and Facilitators? OR should I have three tables for phone numbers, three for emails, three for faxes etc.?

    Many thanks

  2. #2
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    I see a problem with the way you are trying to relate your data. Use the primary key of the phone table as the foreign key on each of your other tables.

    Phones
    -ID (Primary Key)
    -PhoneNumber

    Physicians
    -ID (Primary Key)
    -Name
    -PhoneID (Foreign Key to Phones table)

    Patients
    -ID (Primary Key)
    -Name
    -PhoneID (Foreign Key to Phones table)

    Facilitators
    -ID (Primary Key)
    -Name
    -PhoneID (Foreign Key to Phones table)

  3. #3
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Formatting does not, in most every case, have an effect on the data in the table. You now know this. So, use the table you created to store the literal Autonumber (Primary Key) value in the PersonID field.

    You may be able to manage this third table using Joins and intrinsic referential integrity rules. My preference is to use VBA.

  4. #4
    jlt199 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    34
    Xipooo: That would result in only being able to assign one phone number per patient record, would it not?

    ItsMe: I have no idea what your recommendation was , I'm new to Access and trying to muddle my way through, your suggestion does not look straight-forward for a novice

    Being as I'm new and fairly time restricted should I just make separate tables for each type of person? Another thought, is there a way to make sure that any assigned autonumber is unique to all tables in the database?

    Thanks

  5. #5
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Quote Originally Posted by jlt199 View Post
    Xipooo: That would result in only being able to assign one phone number per patient record, would it not?

    Thanks
    If you are looking to build a Many-To-Many relationship then you use a third table.

    Phones
    -ID
    -Name

    Patients
    -ID
    -Name

    Patients_Phones
    -PatientID
    -PhoneID

    You can either make separate joining tables, one for a patient, one for Physicians, and one for Facilitators or you can make one table with all of the joining information in 4 fields.

    People_Phones
    -PhoneID
    -PhysicianID
    -PatientID
    -FacilitatorID

    The downside of a single table holding all of your linked data is that you'll have 2 null fields for every row.

  6. #6
    jlt199 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    34
    Thanks Xipooo

    Would using a composite key work? I'm currently testing this to see if I can make it work.

    I've added an extra field in the Patients Table, which holds the abbreviation for the table "Pt" in every record. Then in design view selected both TblId and PatientID (using Ctrl) and made them a primary key.

    I've made a relationship to the PhoneNumber table and it seems to be doing what I want it to. Should it do what I want, or is there a reason not to do this?

    Click image for larger version. 

Name:	compositeKey.jpg 
Views:	20 
Size:	18.1 KB 
ID:	15856

    Thanks

  7. #7
    jlt199 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    34
    Nevermind, I see my suggestion isn't going to work.

    What's the argument between using one table for all phone numbers with a separate linking table to each of the different types of people as opposed to have a table for all patient phone numbers, one for all physician numbers and one for all facilitators?

    One gives you a smaller number of overall tables, is that ever a consideration? IS one method more efficient?

    Many thanks

  8. #8
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    I won't have a chance to look at it today but, if you want to submit your DB for review, remove personal data and upload it here.

  9. #9
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    Typically I would write a single table with all of my phone numbers, a separate table for each group of people, and then a separate linking table for each group of people. This will keep things a bit more organized and slimmed down in your database.

  10. #10
    jlt199 is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Feb 2014
    Posts
    34
    Thank you for your responses, I've taken a slightly different route and added a new "People" table that contains all patients, physicians and facilitators. Now everyone in the database has a unique ID and I don't have the problem above.

    Another question though. How much of your data validation do you normally do in the actual tables and how much in the forms? For example, in this database I'm booking patients onto a set of classes. The series is made up of four classes i, ii, iii, iv. To make sure a patient is booked onto one of each of these classes would you set up data validation of the tables and/or build the forms in such a way that that's all patients can be booked on?

    Thanks

  11. #11
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    Keep your tables pristine. Hold the user input, queries in memory and update, append tables after validation.

  12. #12
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332
    To add to what ItsMe said, validate the data AND set up your tables to have as specific of data requirements as you can. The more validation the better.

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

Similar Threads

  1. 1 Form linking to multiple tables
    By jwright77 in forum Forms
    Replies: 12
    Last Post: 08-14-2012, 12:32 PM
  2. Re-linking multiple tables
    By keyel1971 in forum Programming
    Replies: 4
    Last Post: 04-02-2012, 06:16 AM
  3. Replies: 1
    Last Post: 02-27-2012, 05:18 PM
  4. Linking multiple tables
    By anemoskkk in forum Access
    Replies: 0
    Last Post: 04-15-2011, 06:31 PM
  5. Linking a student table to multiple tables
    By iteachyou in forum Access
    Replies: 3
    Last Post: 02-06-2011, 05:53 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