473,778 Members | 1,910 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
22 3228
FishVal
2,653 Recognized Expert Specialist
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, Bridget.

I beg your pardon for the delay. Was very busy.
The cure seems to be simple so far.
Invoke "Requery" method on the combobox as soon as new record was appended to the table.
Smthng like
Expand|Select|Wrap|Line Numbers
  1. Addr1.Requery
after DoCmd block.
Aug 22 '07 #11
banderson
59 New Member
Thanks! I'm now getting an error message that says you have to "save the field before running the requery". I tried to use DoCmd's toopen the table into which the new data is written and then save and close, but this did not work. Is there another way in which I can save the field first before running the requery?

Hi, Bridget.

I beg your pardon for the delay. Was very busy.
The cure seems to be simple so far.
Invoke "Requery" method on the combobox as soon as new record was appended to the table.
Smthng like
Expand|Select|Wrap|Line Numbers
  1. Addr1.Requery
after DoCmd block.
Aug 22 '07 #12
banderson
59 New Member
I'm now trying an alternate way to add new data to a combo box:
I created an "Add Address" button. If the address is not in the combo box, the user clicks on the button, which opens a form "frmAddress " to directly enter data into tblAddr1f. The user can add the new record and click a "Done" button to close the form. On exit, I run the requery. Now when I click on the Addr1 combo box in the frmBuildings the new address is present. I have two questions about this tactic, however:
1) Is there a way to automatically populate the Addr1 control with the newly added address in the record from which I clicked the "Add Address" button?
- Right now, it adds the address to the combo box, but I have to go an select it from the list.
- Another odd thing is that when I close the frmAddress after adding a new record, I view the record from frmBuildings that I was working on. However, when I click on the combo box to select that new address, it jumps me to the first record in the frmBuildings. How do I keep the record I was working on active?

Thanks again in advance for any insight!
Bridget
PS if this is a terribly inefficient way to do udpate a combo box, and I should return to the previous method, please let me know! I just couldn't get the other to work... :(

Thanks! I'm now getting an error message that says you have to "save the field before running the requery". I tried to use DoCmd's toopen the table into which the new data is written and then save and close, but this did not work. Is there another way in which I can save the field first before running the requery?
Aug 22 '07 #13
FishVal
2,653 Recognized Expert Specialist
Thanks! I'm now getting an error message that says you have to "save the field before running the requery". I tried to use DoCmd's toopen the table into which the new data is written and then save and close, but this did not work. Is there another way in which I can save the field first before running the requery?
Hi, Bridget.

Plz, post additional information concerning combobox Addr1
  • RowSource - if it is table post table metadata, if it is query post SQL
  • BoundColumn
Aug 22 '07 #14
FishVal
2,653 Recognized Expert Specialist
I'm now trying an alternate way to add new data to a combo box:
I created an "Add Address" button. If the address is not in the combo box, the user clicks on the button, which opens a form "frmAddress " to directly enter data into tblAddr1f. The user can add the new record and click a "Done" button to close the form. On exit, I run the requery. Now when I click on the Addr1 combo box in the frmBuildings the new address is present. I have two questions about this tactic, however:
1) Is there a way to automatically populate the Addr1 control with the newly added address in the record from which I clicked the "Add Address" button?
- Right now, it adds the address to the combo box, but I have to go an select it from the list.
- Another odd thing is that when I close the frmAddress after adding a new record, I view the record from frmBuildings that I was working on. However, when I click on the combo box to select that new address, it jumps me to the first record in the frmBuildings. How do I keep the record I was working on active?

Thanks again in advance for any insight!
Bridget
PS if this is a terribly inefficient way to do udpate a combo box, and I should return to the previous method, please let me know! I just couldn't get the other to work... :(
Both methods are quite acceptable. The question is what method looks you more suitable? There is even 3rd method. Retrieve into combobox list with a specific row, let us say "Add new address", which when chosen opens form for entering new address record?

What seems to you more suitable? Choose one from the three.

Anyway additional info concerning the combobox would be useful. See my previous post.
Aug 22 '07 #15
banderson
59 New Member
Good morning,

The SQL for my Row Source is:
SELECT qryAddr1f.Addr1 , qryAddr1f.Addr1 ID
FROM qryAddr1f
ORDER BY qryAddr1f.Addr1 ;

The Bound Column is 2
(The Column width is 1";1" ( I remember getting an error message at some point that the Column Width had to match the bound column or something like this...)

Bridget
Hi, Bridget.

Plz, post additional information concerning combobox Addr1
  • RowSource - if it is table post table metadata, if it is query post SQL
  • BoundColumn
Aug 23 '07 #16
banderson
59 New Member
Hi FishVal,
Right now, I am liking the button method - maybe because I actually got it working - sort of... :) If I can fix the issues in my previous post on the button method (copied again below) I'd probably go with this option... As always, any insight greatly appreciated!
Bridget

1) Is there a way to automatically populate the Addr1 control with the newly added address in the record from which I clicked the "Add Address" button?
- Right now, it adds the address to the combo box, but I have to go an select it from the list.
- Another odd thing is that when I close the frmAddress after adding a new record, I view the record from frmBuildings that I was working on. However, when I click on the combo box to select that new address, it jumps me to the first record in the frmBuildings. How do I keep the record I was working on active?

Both methods are quite acceptable. The question is what method looks you more suitable? There is even 3rd method. Retrieve into combobox list with a specific row, let us say "Add new address", which when chosen opens form for entering new address record?

What seems to you more suitable? Choose one from the three.

Anyway additional info concerning the combobox would be useful. See my previous post.
Aug 23 '07 #17
FishVal
2,653 Recognized Expert Specialist
Good morning,

The SQL for my Row Source is:
SELECT qryAddr1f.Addr1 , qryAddr1f.Addr1 ID
FROM qryAddr1f
ORDER BY qryAddr1f.Addr1 ;

The Bound Column is 2


Bridget
Hi, Bridget.

I generally implement the same combo configuration. The code below is a working NotInList handler from one of my DBs.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Addr1_NotInList(NewData As String, Response As Integer)
  2.  
  3.     Dim RS As New ADODB.Recordset
  4.  
  5.     Response = acDataErrContinue
  6.  
  7.     If MsgBox("Dou you want to add " & NewData & " to item names list", _
  8.         vbInformation + vbYesNo, "Add new item confirmation") = vbNo Then Exit Sub
  9.  
  10.     Response = acDataErrAdded
  11.  
  12.     With RS
  13.          .Open Me.Addr1.RowSource, CurrentProject.Connection, _
  14.             adOpenDynamic, adLockOptimistic
  15.         .AddNew
  16.         ![Addr1] = NewData
  17.         .Update
  18.         Me.Addr1 = ![Addr1ID]
  19.         .Close
  20.     End With
  21.  
  22.     Me.Addr1.Requery
  23.  
  24.     Set RS = Nothing
  25.  
  26. End Sub
  27.  
BTW what do you mean by this.
(The Column width is 1";1" ( I remember getting an error message at some point that the Column Width had to match the bound column or something like this...)
To the best of my knowledge column width doesn't have to match anything. At least I've never encountered problem with this.

Regards,
Fish
Aug 23 '07 #18
FishVal
2,653 Recognized Expert Specialist
Hi FishVal,
Right now, I am liking the button method - maybe because I actually got it working - sort of... :) If I can fix the issues in my previous post on the button method (copied again below) I'd probably go with this option... As always, any insight greatly appreciated!
Bridget

1) Is there a way to automatically populate the Addr1 control with the newly added address in the record from which I clicked the "Add Address" button?
- Right now, it adds the address to the combo box, but I have to go an select it from the list.
- Another odd thing is that when I close the frmAddress after adding a new record, I view the record from frmBuildings that I was working on. However, when I click on the combo box to select that new address, it jumps me to the first record in the frmBuildings. How do I keep the record I was working on active?
Hi, Bridget.

Plz post all the code of button_Click procedure.
Basically you need to update your combo with AddrID. But as soon as AddrID is Autonumber you can't do it before you've append new record to tblAddr.
If you append new record via separate form, then there are at least two different approaches.
  • the form where you enter new address update combobox "Addr1", referencing to it via "Forms" collection, e.g.
    Expand|Select|Wrap|Line Numbers
    1. Forms![Main form name]![Subform name]![Addr1] = <New value>
    2.  
  • the button_click code opens the form in modal mode and then updates combobox "Addr1" retrieving last [Addr1] with DMax function.
Anyway forms are separate objects and synchronization between them will require a bit of coding. For example the code must handle such a situation when the form was opened but no record was appended.

Regards,
Fish
Aug 23 '07 #19
banderson
59 New Member
Hi FishVal.
Here is the OnClick code for the btnAddAddr in the main form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnAddAddr_Click()
  2. On Error GoTo Err_btnAddAddr_Click
  3.  
  4.     Dim stDocName As String
  5.     Dim stLinkCriteria As String
  6.  
  7.     stDocName = "frmAddr1"
  8.     DoCmd.OpenForm stDocName, , , stLinkCriteria
  9.     DoCmd.GoToRecord , , acNewRec
  10. Exit_btnAddAddr_Click:
  11.     Exit Sub
  12.  
  13. Err_btnAddAddr_Click:
  14.     MsgBox Err.Description
  15.     Resume Exit_btnAddAddr_Click
  16.  
  17. End Sub
  18.  
This opens frmAddr1 in which I can add a new address.

Then there is a "Done" button in the frmAddr1
The code here for this button is:
Expand|Select|Wrap|Line Numbers
  1. Private Sub btnDone_Click()
  2. On Error GoTo Err_btnDone_Click
  3.  
  4.     DoCmd.Close
  5.  
  6. Exit_btnDone_Click:
  7.     Exit Sub
  8.  
  9. Err_btnDone_Click:
  10.     MsgBox Err.Description
  11.     Resume Exit_btnDone_Click
  12.  
  13. End Sub
  14.  
What happens after I click "Done" is that the frmAddr1 closes and you are back looking at the main form. However, the new address is not showing in the control and when i click on the control to select it, the form jumps back to the first record.

Bridget

Hi, Bridget.

Plz post all the code of button_Click procedure.
Basically you need to update your combo with AddrID. But as soon as AddrID is Autonumber you can't do it before you've append new record to tblAddr.
If you append new record via separate form, then there are at least two different approaches.
  • the form where you enter new address update combobox "Addr1", referencing to it via "Forms" collection, e.g.
    Expand|Select|Wrap|Line Numbers
    1. Forms![Main form name]![Subform name]![Addr1] = <New value>
    2.  
  • the button_click code opens the form in modal mode and then updates combobox "Addr1" retrieving last [Addr1] with DMax function.
Anyway forms are separate objects and synchronization between them will require a bit of coding. For example the code must handle such a situation when the form was opened but no record was appended.

Regards,
Fish
Aug 23 '07 #20

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
2703
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
9629
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
9470
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
10298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9923
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...
0
8957
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5500
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4033
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
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2865
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.