Linking Two Subforms

dtburdick

Registered User.
Local time
Today, 03:15
Joined
Oct 29, 2002
Messages
33
This post is a solution, not a question. It took me a day and a half to find this and it seems to come up often:

I swiped this from: http://www.lunasystems.com/tips.htm

Synchronizing Subforms In Microsoft Access

We're not talking about synchronization from a mainform to a subform but synchronizing two subforms on a mainform. Because the scope of the mainform is the mainform's record source, a subform will not "refresh" unless something on the mainform is changed. When you link two subforms together with a value that is outside the scope of the mainform e.g. a value within the subform, the subforms will not "refresh" (acting as if they are out-of-synch).

The problem: You have a mainform which shows salesperson information. One subform shows the yearly sales totals for that salesperson. The second subform shows a quarterly sales total summary for each year. The link between the Yearly subform and the mainform is salesperson. The link between the Yearly subform and the Quarterly subform is the year from the Yearly subform. But when you select or highlight the Year in the Yearly subform, the quarterly subform does not refresh.

The solution: You need to create a link from the second subform (Quarterly) to the mainform so the data will refresh. Create an unbound text box anywhere on the mainform and delete the label. Open the properties of the new text box and type a new name for the field like txtT-Year then set its Visible property to No. On the control source line type a reference to the year on the Yearly subform e.g. "=[SalesTotalsSubform1].[Form]![T-Year]". Now open the properties for the second subform (order details) change the Child and Master Field Links to: Child = T-Year Master = txtYear. You've now created a field on the mainform that will change each time you select a year which means that now it is within the scope of the main form and will refresh along with the data in the quarterly subform.
 
That method will only work if there is no code on the OnCurrent event of the main subform. If some code does exist you must manually requery the hidden textbox (i.e. add the following to the OnCurrent event in the main subform: Forms![YourFormName]![YourHiddenTextbox].Requery).
 

Users who are viewing this thread

Back
Top Bottom