473,666 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

inconsistent behavior of form / subform link

59 New Member
Hello all,
I am hoping that you can help me with a problem that has occurred numerous times on various forms in the two databases that I am working on. When I first add a subform to a form linking child and master fields (primary key and foreign key), the subform will automatically update when the master field on the main form is changed (it is in a combo box). However, when I work more on the form - making it a bit more complicated, adding code, search boxes, etc. The subform stops updating, but rather stays on one record even when the master field is changed (when a new value is selected from the combo box that has the master field as its bound column).

I have tried using Me.Requery in the AfterUpdate Event of the combo box, but this requeries the entire form's contents, resetting it to the first record. I have also tried Me.[SUBFORMNAME].Requery, but this does not seem to work.

Does anyone know why this feature – the automatic link between child and master fields does not always work? Or why requerying the subform itself does not work? I would appreciate any suggestions.

Many thanks, in advance.
Bridget
Oct 23 '08 #1
12 3021
NeoPa
32,568 Recognized Expert Moderator MVP
I'm not very experienced in this area I'm afraid Bridget, but I think you should probably be looking more closely at axactly what you are doing when you think it's no longer working. My guess is that what you are doing makes it stop working, rather than it being a flaw in the system itself. Pay particular attention when it next happens and find out what exactly is occurring. That way someone may be able to explain why for you.
Oct 24 '08 #2
Stewart Ross
2,545 Recognized Expert Moderator Specialist
Hi Bridget. I agree entirely with NeoPa - this is something that has been introduced by the actions you are taking. In extensive use of subforms I have never had issues relating to incorrect synchronisation of master-detail records the way you describe.

Could you clarify what you mean when you talk about selecting a new primary key value for the master field? It is most unusual to have to change the primary key for the one-side record at all, particularly when there are already many-side records in existence. It is not the job of a subform to change secondary keys in such circumstances. Even with Cascade Updates on for your 1-many relationship concerned such a change will not be reflected correctly into many-side records automatically, as Cascade Updates handles modifications to existing key values, not wholesale replacement of those values.

The parent-child relationship of a main-form sub-form combination takes care of the creation of related secondary keys automatically. However, if you change the primary key to a different one subforms cannot of themselves change the secondary key values to something else - and it is not reasonable to expect them to.

In any event, if you have relational integrity checking set for the relationship concerned (and you should) Access will simply not allow you to replace a primary key if to do so would leave 'orphaned' many-side records that no longer match to a one-side record.

-Stewart
Oct 24 '08 #3
banderson
59 New Member
Thank you NeoPa and Stewart for your responses. I think this may reveal a flaw in my understanding of how forms can /should connect. Let me give a specific example and see if that helps to shed some more light on it.

I have two forms “frmAddSites” and “sfrmAddr1” that are linked in a form/subform relationship:

“frmAddSites” has a control source, tblSites.
The table, tblSites, includes:
SiteID – primary key, autonumber
SiteName – text
Addr1LKUP – number, foreign key to an address table called “tluAddr1”.
(and a few other descriptive fields)

The table, tluAddr1, includes the fields:
Addr1ID – primary key, autonumber
Addr1 – text
ZipCodeLKUP – number, foreign key to a zipcode table tluZipCode.

The table, tluZipCode, holds the city and state information for each zip code:
Zipcode – primary key
PostalCityLKUP – number, foreign key to tluPostalCity
StateLKUP – number, foreign key to tluState
“sfrmAddr1” has a control source, qryAddr1.
The query, qryAddr1, holds all of the address information from tluAddr1 and associated lookup tables (see above):
Addr1ID
Addr1
PostalCity
State
ZipCode
“frmAddSites” has the following controls:
txtSiteID - text box for SiteID
txtSiteNm - text box for SiteName
cboAddr1 - combo box for Addr1LKUP.
The row source for the cboAddr1 is qryAddr1 (bound column is Addr1ID, visible column is Addr1)

“sfrmAddr1” has the following controls:
txtAddr1ID - text box for Addr1ID
txtCity - text box for PostalCity
txtState - text box for State
txtZipCode - text box for ZipCode

The two forms are linked by
Master Field Addr1LKUP
Child Field Addr1ID

The functionality I am hoping for is to be able to choose an address from the cboAddr1 on the main form (frmAddSites) and have the subform (sfrmAddr1) automatically display the associated City, State and ZipCode.

The code Me.Requery in the AfterUpdate Event of cboAddr1 requeries the entire form, but also jumps to the first record.
The code Me.sfrmAddr1.Re query does not seem to do anything.
If I change the selection in cboAddr1 on a record, then move to another record, and go back to the record where I changed the combo box selection, the correct record on the subform is displayed.

Does this make more sense?
Is this inherently a problematic way to link a form and subform?
Is there a way to make the subform display the correct record when the linked field changes in the main form?

Thanks again,
Bridget
Oct 27 '08 #4
NeoPa
32,568 Recognized Expert Moderator MVP
That's a lot to go through Bridget, but I did see your .Requery request for the subform (which failed) and I think that's related to referencing the item correctly. Check out (Referring to Items on a Sub-Form).
Oct 27 '08 #5
banderson
59 New Member
Thanks, NeoPa. Sorry for all the details before, I was trying to be thorough, but maybe it was too much...

I have looked at the "referring to items on a sub-form" and other postings about properly referencing subforms. Using these, I have tried many iterations of the requery code without success. I would like to requery the entire subform, and so my understanding is that I want to reference the form as a control of the main form, rather than a control within the subform. Here is what I have tried, without success.
Me.sfrmAddr1.re query
Me!sfrmAddr1.re query
Forms![frmAddSites]![sfrmAddr1].requery
Forms![frmAddSites]![sfrmAddr1].Form.requery

Do you see an obvious mistake in my referencing of the subform for requery?

I found the posting: http://bytes.com/forum/thread628289.ht ml
in which someone has similar problems requerying a subform and he ends up scrapping requery altogether and instead resets the recordset clone. His code is more complicated than I need (and frankly than I understand.), though I have had success using code to set a recordset clone for other purposes (i.e. using a combo box to filter a form). I am going to try this tactic to see if it works better than the requery option.

Thanks again for any help.
Bridget



That's a lot to go through Bridget, but I did see your .Requery request for the subform (which failed) and I think that's related to referencing the item correctly. Check out (Referring to Items on a Sub-Form).
Oct 27 '08 #6
NeoPa
32,568 Recognized Expert Moderator MVP
...
Forms![frmAddSites]![sfrmAddr1].Form.requery
...
This would be correct if the SubForm/SubReport control on your form were named thus. I suspect this is actually the name of the form that you put IN the subform control.

Find the name of your SubForm/SubReport control on [frmAddSites] and use that instead.
Oct 27 '08 #7
banderson
59 New Member
Thanks, NeoPa.
Sigh. I just think I'm getting the hang of Access/vba and then realize how much I don't really get...
Thanks again
Bridget
Oct 29 '08 #8
NeoPa
32,568 Recognized Expert Moderator MVP
Did you manage to get it to work Bridget?
Oct 29 '08 #9
banderson
59 New Member
Thanks for asking.
My subform and the name of the subform control are both "sfrmAddr1" . Is it problematic to name the subform control the same as the subform itself?

I am making some progress in understanding requerying, but this issue is still a mystery: how to call a requery of a subform from the AfterUpdate_Eve nt of a control in the main form.

If I requery a subform from the subform itself (using Me.Requery), it works fine. However, I cannot get it to work by calling it from the main form.

I welcome more suggestions and will post if/when I find a solution.
Bridget
Oct 30 '08 #10

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

Similar topics

5
3517
by: Michelle | last post by:
Hi all Is it possible to have 2 subforms on a form but have the second subform linked to the 1st subform. I will explain the situation. My form contains details of teams and the shift the team is working on a particular day. The 1st subform contains the names of the team members. As the user moves through the records on the main form, the team members are updated accordingly. The 1st subform is a continuous form.
1
1732
by: Richard Hollenbeck | last post by:
I'm getting errors. Access is telling me that it can't add a record. I have a table of college courses and a linked table of groups of activities in that course as a linked table (one course to many groups of activities). "Groups" include things like Participation, Exams, Essays, Etc., Etc., Etc. I have a main form showing the course information (courseID, courseDescription, courseStartDate courseEndDate, etc.) and a sub-form showing the...
1
2015
by: Steve Miles | last post by:
I've got a form with a combo box and begin/end dates. When any of the three are changed I set a subform's recordsource so the records returned are filtered based on the three fields. The syntax I'm using is: Me.{subform-name}.Form.RecordSource = "Select * from tbl..." ....including the three fields in the SQL Where clause. This method works well, but mysteriously stops returning any rows once in a while. I can hard-code the SQL to...
4
7002
by: Dave Boyd | last post by:
Hi, I have two very similar forms each with a subform. The main form gets a few fields from the user and passes this back to a query that the subform is bound to. The requery is done when the user enters the last qualifying field on the main form. In one case this works fine, the subform shows the data the user wants to update -- which means showing all the data put in previously (ie showing this via the requery and the continuous...
14
3097
by: alwayshouston | last post by:
Hi All! I am working on this very small database and I am confused in the designing a simple form. I only have three tables in the database. First Table: tblExpense Columns: ExpenseID ; ExpenseType Data: 1 ; FOOD 2 ; AIRLINE 3 ; FARE
4
5571
by: jcazmail-groups | last post by:
I have a child form that has a combo box whose underlying query needs to be filtered by a value from a combo box on the parent form. I have succeeded in doing this by putting the following SQL in the rowsource of the combobox: SELECT tblForms.idForms, tblForms.FormNumber, tblForms.FormName, tblForms.idCustomers FROM tblForms ORDER BY tblForms.FormNumber; Then I adding the following to the GotFocus event of the combo box and
3
2406
by: virtualgreek | last post by:
Dear all, I have a scenario that is driving me nuts. (MS Access 2003) I have a form/subform (Continuous form) where it gets its data from tables Order and Order_Details. In the footer section of the subform I have a hidden textbox named txtOrder_Total_Amount which displays the total of the whole order. On the main form I have a bound contol from the Order table, namely Order.Order_Total_Amount_Euro On the subform I have fields such...
2
8382
by: darnel | last post by:
I have 4 hierarchical tables and want to display it all together as a form and 3 subforms, when subform displays (and allow to add/edit) only relevant items from each superior subform. Tables are: Clients --> linked thru id_client --> Orders --> linked thru id_order --> Licences --> linked thru id_licence --> Regkeys Access' Form Wizard allows only form + 2 subforms. I tried to create last subform and its link manually, but I'm not...
4
1430
by: sparks | last post by:
TRYING TO USE SHORT NAMES might make more since. I have a main form and its tied to tblmain subform1 and it is tied to tbl1 subsubformA on subform1 tied to tbl2 MAIN---tblmain----autoid subform1----tbl1----ID subsubform1----tbl2----ID
0
8445
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
8871
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...
1
8551
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7386
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...
1
6198
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
5664
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4198
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
4369
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2011
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.