I'm building a simple database (well, I thought it would be) to record personnel names and phone numbers. Each person could have multiple phone numbers (Home, Office, or Mobile). So to record these, I need a main form showing the first and last names of a person, and a subform showing the first/last names and their phone number(s) and type of number. So like this:
Main Form
Person ID: ________
First Name: _________
Last Name: __________
Subform
Person ID: ________
First Name: _________
Last Name: __________
Phone No. Type: _________
Phone No.: __________
To do this I've built four tables:
AllContacts
PersonID (master key)
FirstName
LastName
PhoneNumbers
PhoneNumberID (master key)
PhoneNumberType ID (foreign key)
PhoneNumber
PersonID (foreign key)
PhoneNumberType
PhoneNumberType ID (master key)
PhoneNumberType Name (like Home, Office, Mobile)
ContactsAndPhon eNumbers
PhoneDataID (master key)
PersonID (foreign key)
PhoneNumberType ID (foreign key)
PhoneNumberID (foreign key)
and set all relationships among them. I've populated the AllContacts and PhoneNumbers table with test data.
The problem is that the subform shows the field headings but no records, and remains blank when the main form record changes; i.e., when I change the person in the main form. It's as if there's no connection between the main form and the subform.
The Link Master Fields and Link Child Fields of the subform are both PersonID. The subform's Record Source is:
That SQL query was constructed by Access. How do I establish a connection between the forms so the subform changes along with the main form?
Main Form
Person ID: ________
First Name: _________
Last Name: __________
Subform
Person ID: ________
First Name: _________
Last Name: __________
Phone No. Type: _________
Phone No.: __________
To do this I've built four tables:
AllContacts
PersonID (master key)
FirstName
LastName
PhoneNumbers
PhoneNumberID (master key)
PhoneNumberType ID (foreign key)
PhoneNumber
PersonID (foreign key)
PhoneNumberType
PhoneNumberType ID (master key)
PhoneNumberType Name (like Home, Office, Mobile)
ContactsAndPhon eNumbers
PhoneDataID (master key)
PersonID (foreign key)
PhoneNumberType ID (foreign key)
PhoneNumberID (foreign key)
and set all relationships among them. I've populated the AllContacts and PhoneNumbers table with test data.
The problem is that the subform shows the field headings but no records, and remains blank when the main form record changes; i.e., when I change the person in the main form. It's as if there's no connection between the main form and the subform.
The Link Master Fields and Link Child Fields of the subform are both PersonID. The subform's Record Source is:
Code:
SELECT [AllContacts].[PersonID]
, [PhoneNumbers].[PhoneNumber]
, [ContactsAndPhoneNumbers].[PhoneDataID]
, [PhoneNumberType].[PhoneNumberTypeName]
FROM PhoneNumberType
INNER JOIN (
(AllContacts
INNER JOIN PhoneNumbers
ON AllContacts.PersonID
=PhoneNumbers.PersonID)
INNER JOIN ContactsAndPhoneNumbers
ON AllContacts.PersonID
=ContactsAndPhoneNumbers.PersonID)
ON PhoneNumberType.PhoneNumberTypeID
=ContactsAndPhoneNumbers.PhoneNumberTypeID;
Comment