473,769 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

managing multiple related subforms and many to many relationships

59 New Member
Hello I'm new to developing databases in Access and using Access2003. I have a dataset with a few many to many relationships that I have created linking tables for to make multiple 1:M relationships.
My problem is trying to figure out a set of forms and subforms for this data in which the users can enter new data in a straightforward way. In my dataset there are: Buildings, Contacts, addresses for buildings and contacts, and different types of contacts. The contact types are super, manager, and volunteer.
Here are the relationships:
- A building has more than one contact and a contact can be associated with more than one building. (M:M)
- contact can be more than one type (1:M)
- an address can be associated with more than one contact (1:M).
- a building is associated with one address. (1:1)

Here is how I set up my tables:

tblBldg
BldgID PK
BldgName
(other unique bldg attributes)
AddrID FK

tblContacts
ContactID PK
ContactNmLast
ContactNmFirst
(other unique contact attributes)

tblContactTypes
TypeID PK
TypeNm

tbl Addresses
AddrID PK
StreetAddr
City
State
ZipCode

tblContactTypeU Q
ContactTypeID PK
ContactID
TypeID

tblContactTypeA ddr
ContactTypeID
AddrID

tblBldgContactT ype
BldgID
ContactTypeID

Specifically, I tried to set up a form starting with Buildings that had subforms in which you can view the building address and the multiple contacts associated with a building and their attributes (including their addresses - a nested subform under Contacts). When I add a new building name in the main form and then try to add an address for that building in the adress subform (to be entered in the address table) it will not let me b/c there is not already an ID for the Address that I want to add. Also, when I try to add a contact and its related data in the contact subform, the linking tables do not update (the tbl BldgContactType table or a record is not added to the tblContactTypeU Q table). Same for the table linking ContactTypeID and AddrID.
Please advise!
thanks in advance.
Bridget
Aug 17 '07 #1
22 3224
FishVal
2,653 Recognized Expert Specialist
Hello I'm new to developing databases in Access and using Access2003. I have a dataset with a few many to many relationships that I have created linking tables for to make multiple 1:M relationships.
My problem is trying to figure out a set of forms and subforms for this data in which the users can enter new data in a straightforward way. In my dataset there are: Buildings, Contacts, addresses for buildings and contacts, and different types of contacts. The contact types are super, manager, and volunteer.
Here are the relationships:
- A building has more than one contact and a contact can be associated with more than one building. (M:M)
- contact can be more than one type (1:M)
- an address can be associated with more than one contact (1:M).
- a building is associated with one address. (1:1)

Here is how I set up my tables:

tblBldg
BldgID PK
BldgName
(other unique bldg attributes)
AddrID FK

tblContacts
ContactID PK
ContactNmLast
ContactNmFirst
(other unique contact attributes)

tblContactTypes
TypeID PK
TypeNm

tbl Addresses
AddrID PK
StreetAddr
City
State
ZipCode

tblContactTypeU Q
ContactTypeID PK
ContactID
TypeID

tblContactTypeA ddr
ContactTypeID
AddrID

tblBldgContactT ype
BldgID
ContactTypeID

Specifically, I tried to set up a form starting with Buildings that had subforms in which you can view the building address and the multiple contacts associated with a building and their attributes (including their addresses - a nested subform under Contacts). When I add a new building name in the main form and then try to add an address for that building in the adress subform (to be entered in the address table) it will not let me b/c there is not already an ID for the Address that I want to add. Also, when I try to add a contact and its related data in the contact subform, the linking tables do not update (the tbl BldgContactType table or a record is not added to the tblContactTypeU Q table). Same for the table linking ContactTypeID and AddrID.
Please advise!
thanks in advance.
Bridget
Hi, Bridget.

Your current tables set does not seem to be optimal.
  • You say
    "a building is associated with one address. (1:1)".
    What is the reason to make 2 tables for buildings and addresses? 1:1 relationship is worth in a case when FK-side table supposed to have 1 record or not to have record at all and the record is space consuming (e.g. Memo or OLE). In your case I don't see a reason why not to merge these tables.
  • You say
    "- A building has more than one contact and a contact can be associated with more than one building. (M:M)
    - an address can be associated with more than one contact (1:M)",
    but these is impossible as soon as building is associated with 1 address only. What do you actually mean here?
  • and the last but not the least. You should have an intermediate table to implement M:M relationship between tblBldg and tblContacts
Aug 17 '07 #2
banderson
59 New Member
Thank you for your reply!
The problem with the addresses in my dataset is that I'm trying to avoid duplicate entry of addresses. A building has one address, yes. Contacts that live in the building have the same address plus an apartment or suite number. So one address can be associated with a building and one or more contacts. A further complicating issue is that the contacts for a building do not always live in that building, and thus their address is different from the building address. For example, a super linked to a particular building may or may not live in the building. Same for a manager of a building. And, here is the kicker... one contact might be a vounteer in a building AND the manager of that building. This person, therefore, might have two addresses - one when wearing the volunteer hat and a different one when wearing the manager hat (b/c the management office is in a different location.)

To get around this, I was trying to use a single address table whose records could be linked to buildings and contacts of different types. I thought if I made a ContactTypeUQ table linking unique combinations of contacts and contact types, I could then associate an address for each unique combination of contact and contact type. This address could then also be linked to a building by including the addrID in the tblBuilding table. Additionally, I need to link each building with its multiple contacts. As you can see it gets complicated quickly!
Please, if you have suggestions as to a better way to set up the tables I would love advice.

Thanks again in advance.
Bridget

Hi, Bridget.

Your current tables set does not seem to be optimal.
  • You say
    "a building is associated with one address. (1:1)".
    What is the reason to make 2 tables for buildings and addresses? 1:1 relationship is worth in a case when FK-side table supposed to have 1 record or not to have record at all and the record is space consuming (e.g. Memo or OLE). In your case I don't see a reason why not to merge these tables.
  • You say
    "- A building has more than one contact and a contact can be associated with more than one building. (M:M)
    - an address can be associated with more than one contact (1:M)",
    but these is impossible as soon as building is associated with 1 address only. What do you actually mean here?
  • and the last but not the least. You should have an intermediate table to implement M:M relationship between tblBldg and tblContacts
Aug 17 '07 #3
FishVal
2,653 Recognized Expert Specialist
Thank you for your reply!
The problem with the addresses in my dataset is that I'm trying to avoid duplicate entry of addresses. A building has one address, yes. Contacts that live in the building have the same address plus an apartment or suite number. So one address can be associated with a building and one or more contacts. A further complicating issue is that the contacts for a building do not always live in that building, and thus their address is different from the building address. For example, a super linked to a particular building may or may not live in the building. Same for a manager of a building. And, here is the kicker... one contact might be a vounteer in a building AND the manager of that building. This person, therefore, might have two addresses - one when wearing the volunteer hat and a different one when wearing the manager hat (b/c the management office is in a different location.)

To get around this, I was trying to use a single address table whose records could be linked to buildings and contacts of different types. I thought if I made a ContactTypeUQ table linking unique combinations of contacts and contact types, I could then associate an address for each unique combination of contact and contact type. This address could then also be linked to a building by including the addrID in the tblBuilding table. Additionally, I need to link each building with its multiple contacts. As you can see it gets complicated quickly!
Please, if you have suggestions as to a better way to set up the tables I would love advice.

Thanks again in advance.
Bridget
Well, Bridget. This is quite acceptable. But why buildings and addresses are associated with contact types rather than with contacts?
Aug 18 '07 #4
banderson
59 New Member
The addresses / buildings need to be associated with unique combinations of contacts / types (e.g. John Doe is a volunteer of one building - with one address - and also acts as a manager of another building - with another address. So address 1 is for John Doe as a volunteer and address 2 is for John Doe as a manager.) I thought making a table with unique combinations of contacts and types would allow me to do this, however, when I try to create the forms, the link table does not get updated when I enter a new Contact.

Also, when generating a form with tblBuildings as the main table, and address as a subform, I can enter a new building name, but then when I try to enter the address for this building in the subform, I get an error message that I cannot add or edit a record because a record is required in the tblAddress table.

I guess I do not understand how to work with link tables (used to get around M:M relationships) in forms. If you have any reference materials that might help with this, I would be very appreciative.
Bridget

Well, Bridget. This is quite acceptable. But why buildings and addresses are associated with contact types rather than with contacts?
Aug 20 '07 #5
FishVal
2,653 Recognized Expert Specialist
The addresses / buildings need to be associated with unique combinations of contacts / types (e.g. John Doe is a volunteer of one building - with one address - and also acts as a manager of another building - with another address. So address 1 is for John Doe as a volunteer and address 2 is for John Doe as a manager.) I thought making a table with unique combinations of contacts and types would allow me to do this, however, when I try to create the forms, the link table does not get updated when I enter a new Contact.

Also, when generating a form with tblBuildings as the main table, and address as a subform, I can enter a new building name, but then when I try to enter the address for this building in the subform, I get an error message that I cannot add or edit a record because a record is required in the tblAddress table.

I guess I do not understand how to work with link tables (used to get around M:M relationships) in forms. If you have any reference materials that might help with this, I would be very appreciative.
Bridget
Hi, Bridget.

Here is what I'd like to suggest you.
  • concerning main form representing [tblBldg] 1:1 [tbl Addresses]
    make a query where the tables are joined
    Expand|Select|Wrap|Line Numbers
    1. SELECT tblBldg.*, [tbl Addresses].* FROM tblBldg INNER JOIN [tbl Addresses] ON tblBldg.[AddrID] = [tbl Addresses].[AddrID] 
    then build a form based on this query
  • concerning subform representing building contacts, I suggest you to build it based on [tblBldgContactT ype] joined with [tblContactTypeU Q], something like
    Expand|Select|Wrap|Line Numbers
    1. SELECT tblBldgContactType.BldgID, tblContactTypeUQ.ContactID, tblContactTypeUQ.TypeID FROM tblBldgContactType INNER JOIN tblContactTypeUQ ON tblBldgContactType.ContactTypeID = tblContactTypeUQ.ContactTypeID 
    and link via MasterField = tblBldg.BldgID, ChildField = tblBldgContactT ype.BldgID of course
    surely you will get 2 comboboxes limited to list, the common approach is to add new items to list handling NotInList event (where are many posts on the forum concerning this and I as well will be glad to help you with this rather simple coding)
  • and finally to the subform above mentioned oadd a subform based on [tbl Addresses]

BTW, the last question: what type is your PK fields? Autonumber?

Keep online. :)

regards
Fish
Aug 20 '07 #6
banderson
59 New Member
Hello Fish,
Thank you for these suggestions. I will try them and post back if I have any problems. I will also look for NotInList Event postings in the forum as well. (Knowing the right the search terms to use is half the battle!)
And, yes, all of my PK's are autonumber. If you have an alternate suggestion, please let me know. Elsewhere I've read about using composite primary keys in associate tables that consist of the foreign keys of the primary tables, but have yet to figure out why this is advantageous over making a new primary key.

Bridget


Hi, Bridget.

Here is what I'd like to suggest you.
  • concerning main form representing [tblBldg] 1:1 [tbl Addresses]
    make a query where the tables are joined
    Expand|Select|Wrap|Line Numbers
    1. SELECT tblBldg.*, [tbl Addresses].* FROM tblBldg INNER JOIN [tbl Addresses] ON tblBldg.[AddrID] = [tbl Addresses].[AddrID] 
    then build a form based on this query
  • concerning subform representing building contacts, I suggest you to build it based on [tblBldgContactT ype] joined with [tblContactTypeU Q], something like
    Expand|Select|Wrap|Line Numbers
    1. SELECT tblBldgContactType.BldgID, tblContactTypeUQ.ContactID, tblContactTypeUQ.TypeID FROM tblBldgContactType INNER JOIN tblContactTypeUQ ON tblBldgContactType.ContactTypeID = tblContactTypeUQ.ContactTypeID 
    and link via MasterField = tblBldg.BldgID, ChildField = tblBldgContactT ype.BldgID of course
    surely you will get 2 comboboxes limited to list, the common approach is to add new items to list handling NotInList event (where are many posts on the forum concerning this and I as well will be glad to help you with this rather simple coding)
  • and finally to the subform above mentioned oadd a subform based on [tbl Addresses]

BTW, the last question: what type is your PK fields? Autonumber?

Keep online. :)

regards
Fish
Aug 20 '07 #7
FishVal
2,653 Recognized Expert Specialist
Hello Fish,
Thank you for these suggestions. I will try them and post back if I have any problems. I will also look for NotInList Event postings in the forum as well. (Knowing the right the search terms to use is half the battle!)
And, yes, all of my PK's are autonumber. If you have an alternate suggestion, please let me know. Elsewhere I've read about using composite primary keys in associate tables that consist of the foreign keys of the primary tables, but have yet to figure out why this is advantageous over making a new primary key.

Bridget
Hi, Bridget.

Everything is ok with Autonumber PK.
Personally I use only Autonumber fields as PKs. :)
And what concerning composite keys, I think the only advantage is to prevent records duplication, but the same could be easily achieved by adding multifield index.
Aug 20 '07 #8
banderson
59 New Member
Hi FishVal,
I found some code online to enable the ability to add new records to a combo box (NotInList Event). I am trying it with my address combo box, however it is not quite working. If a new address is entered into the combo box, it asks you if you want to add the new entry to the list. If you click yes, the new entry should, in theory, be added to the list. If you click no, it should prompt you to choose from the list. What happens now, is that if you click yes, it tells you that it was added to the list, but then gives an error and it tells you that it cannot add it to the list. I don't know enough about writing code yet to know where it is going wrong. Below is the code. Any insight is appreciated! Thanks in advance.
Bridget

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Addr1_NotInList(NewData As String, Response As Integer)
  2.     On Error GoTo Addr1_NotInList_Err
  3.     Dim intAnswer As Integer
  4.     Dim strSQL As String
  5.     intAnswer = MsgBox("The address " & Chr(34) & NewData & _
  6.         Chr(34) & " is not currently listed." & vbCrLf & _
  7.         "Would you like to add it to the list now?" _
  8.         , vbQuestion + vbYesNo, "Street Addresses")
  9.     If intAnswer = vbYes Then
  10.         strSQL = "INSERT INTO tblAddr1f([Addr1]) " & _
  11.                  "VALUES ('" & NewData & "');"
  12.         DoCmd.SetWarnings False
  13.         DoCmd.RunSQL strSQL
  14.         DoCmd.SetWarnings True
  15.         MsgBox "The new address has been added to the list." _
  16.             , vbInformation, "Street Addresses"
  17.         Response = acDataErrAdded
  18.     Else
  19.     MsgBox "Please choose a job title from the list." _
  20.         , vbInformation, "Street Address"
  21.     Response = acDataErrContinue
  22.     End If
  23. Addr1_NotInList_Exit:
  24.     Exit Sub
  25. Addr1_NotInList_Err:
  26.     MsgBox Err.Description, vbCritical, "Error"
  27.     Resume Addr1_NotInList_Exit
  28. End Sub 
Hi, Bridget.

Everything is ok with Autonumber PK.
Personally I use only Autonumber fields as PKs. :)
And what concerning composite keys, I think the only advantage is to prevent records duplication, but the same could be easily achieved by adding multifield index.
Aug 22 '07 #9
banderson
59 New Member
The error message is:
The text you entered isn’t an item in the list.
Select an item from the list or enter text that matches one of the listed items.

It appears as though it refuses to enter the data into the table after telling you it did enter the new data.

Hi FishVal,
I found some code online to enable the ability to add new records to a combo box (NotInList Event). I am trying it with my address combo box, however it is not quite working. If a new address is entered into the combo box, it asks you if you want to add the new entry to the list. If you click yes, the new entry should, in theory, be added to the list. If you click no, it should prompt you to choose from the list. What happens now, is that if you click yes, it tells you that it was added to the list, but then gives an error and it tells you that it cannot add it to the list. I don't know enough about writing code yet to know where it is going wrong. Below is the code. Any insight is appreciated! Thanks in advance.
Bridget

Expand|Select|Wrap|Line Numbers
  1.  Private Sub Addr1_NotInList(NewData As String, Response As Integer)
  2.     On Error GoTo Addr1_NotInList_Err
  3.     Dim intAnswer As Integer
  4.     Dim strSQL As String
  5.     intAnswer = MsgBox("The address " & Chr(34) & NewData & _
  6.         Chr(34) & " is not currently listed." & vbCrLf & _
  7.         "Would you like to add it to the list now?" _
  8.         , vbQuestion + vbYesNo, "Street Addresses")
  9.     If intAnswer = vbYes Then
  10.         strSQL = "INSERT INTO tblAddr1f([Addr1]) " & _
  11.                  "VALUES ('" & NewData & "');"
  12.         DoCmd.SetWarnings False
  13.         DoCmd.RunSQL strSQL
  14.         DoCmd.SetWarnings True
  15.         MsgBox "The new address has been added to the list." _
  16.             , vbInformation, "Street Addresses"
  17.         Response = acDataErrAdded
  18.     Else
  19.     MsgBox "Please choose a job title from the list." _
  20.         , vbInformation, "Street Address"
  21.     Response = acDataErrContinue
  22.     End If
  23. Addr1_NotInList_Exit:
  24.     Exit Sub
  25. Addr1_NotInList_Err:
  26.     MsgBox Err.Description, vbCritical, "Error"
  27.     Resume Addr1_NotInList_Exit
  28. End Sub 
Aug 22 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

17
1856
by: Steve Jorgensen | last post by:
Terminology question: Is there a term for a set of records related directly or indirectly by key value in several tables? For example, a single invoice record and its line item records -or- a single customer, the customer's orders, the order lines for those orders, the customer's invoices, and the invoice lines for those invoices. I'm thinking the term might be graph, but I'm not at all certain of this.
3
8230
by: SuryaPrakash Patel via SQLMonster.com | last post by:
Hello, There are three tables: OS-GroupOFCompanies (Table1) GoC_GroupOFCompaniesID (PK) OS-Organization (Table 2) Org_OrganizationID (PK)
0
2702
by: misscrf | last post by:
I am currently working on a database, in 3rd normal form, which is for candidates who apply for a job with the law firm that I workd for. My issue is with good form design. I have a main form. Then I have 3 pages on a tab control ( 4 if the type of candidate validates that is is to be shown) Each page has a subform. The subforms can be either single or continuous, I think I am still deciding what I want to lock down this entry...
11
4533
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my database,just help in getting me pointed in the right direction. I have a database with 8 tables, which from what I have read, cannot be linked on a single form, and be updatable. I have created a query which includes all 8 tables, and then...
8
10417
by: Jason L James | last post by:
Hi all, does anyone know if I can create a dataview from multiple datatables. My dataset is constructed from four separate tables and then the relationships are added that link the tables together. To make data entry easier I would like to combine selected columns from the four tables onto a single dataview that could be used as the datasource for a datagrid control. The distinct updates, insert ans delete
11
3680
by: shriil | last post by:
Hi I have this database that calculates and stores the incentive amount earned by employees of a particular department. Each record is entered by entering the Date, Shift (morn, eve, or night) and the 'employee name'. There is another table which assigns an ID to the Shifts, i.e. 1,2 and 3 for morn, eve & night shifts respectively. From the mother table, the incentive is calculated datewise for each employee as per his shift duty. In...
3
1786
by: BASSPU03 | last post by:
I had to present my DB today, but was granted a chance to fix something about it. In order to fix something, I added something...something that is giving me more trouble than it should. I have to present again tomorrow. Quick assistance would be greatly appreciated. I have three forms (one main form and two subforms) with the following fields: frmResultsFY FiscalYear sfrmResultsAgencies FiscalYear Agency
0
1649
by: cannonpm | last post by:
Greetings and salutations. I have developed an A2K3 MDB and have a search form modeled after Allen Browne's search form (http:// allenbrowne.com/ser-62.html). It works well except for records which have multiple related records in 1:many relationships and many:to:many relationships. To view my results, I created a query called qryAllData which contains all of the data from several tables for each record. For example, say I have one...
3
2588
by: 6afraidbecause789 | last post by:
Think school - students - discipline interventions - misbehaviors - staff for this one....On a mainform frmStudentInterventions, I have linked a subform (sfrmMisbehaviors) with another subform (sfrmInterventions) with the Child and Master fields "InterventionID." This is tested and works - as users click through the continuous list of interventions, the continuous list of misbehaviors changes per intervention. Now, I need to link another...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9420
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7401
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5441
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.