Event to sync subform A with subform B (1 Viewer)

sxschech

Registered User.
Local time
Today, 02:21
Joined
Mar 2, 2010
Messages
792
Built a form with a datasheet view subform. I now need to add a second datasheet subform dependent on a value from the first subform. I found this link that suggests placing a text box on main form to capture the value. http://www.fmsinc.com/MicrosoftAccess/Forms/Synchronize/LinkedSubforms.asp

Here is the issue, I know the field that needs to be obtained, but I want to have the value posted to the main form based on the currently selected row of the subform data sheet. Whichever row or field user single clicks on is what should trigger the event. I tried the click event of the subform and it didn't fire. I also tried the click event of the detail and that did not fire either.

I don't want it based on having to click or double click the specific field as would prefer the second form to be populated based on what row the user is working on in the first subform rather than having to tell them in order to see the correct data you need to click on the "product code" field as the product code field already has an event tied to it. The other reason is that the first subform will display multiple product codes, so if user doesn't remember to click on the product code, the second subform won't reflect the data for the specific product code. If you need more clarification, please let me know.
 

MarkK

bit cruncher
Local time
Today, 02:21
Joined
Mar 17, 2004
Messages
8,180
Lets say you have a Form1 with two subform controls SFM1 and SFM2, and lets say the hosted subforms are called fSFM1 and fSFM2.
Now, you should be able to put a hidden textbox, say txtLink, on Form1 that exposes a field value, say Field1, from fSFM1 if you set its ControlSource to...
Code:
[COLOR="Green"]'this is the ControlSource property of the hidden textbox txtLink[/COLOR]
=[SFM1].[Form].[Field1]
Before hiding that control, confirm that as you navigate in fSFM1 that the value in txtLink changes, and is correct.

With that done, you should now be able to link the second subform to that textbox value by editting the LinkMasterFields and LinkChildFields properties of the subform control SFM2. LinkMasterFields should be the name of the hidden textbox "txtLink" (without the quotes). LinkChildFields should be the field name on fSFM2 that performs the link at that end, say, Field2.

With that done, navigation in fSFM1 will cause txtLink to change (as tested above) and that change. mediated by the LinkMasterFields and LinkChildFields properties of the SFM2 subform control, will filter that subform to only show rows where Field2 in fSFM2 is equal to Field1 in fSFM1.

Does that make sense? Can you follow that?
Mark
 

sxschech

Registered User.
Local time
Today, 02:21
Joined
Mar 2, 2010
Messages
792
Thank you. It works. :)

After seeing your explanation, I guess I was overthinking it that the value could only get onto the main form when an event takes place.
 

MarkK

bit cruncher
Local time
Today, 02:21
Joined
Mar 17, 2004
Messages
8,180
You could use an event. It might be a little faster if you do, rather than waiting for the form infrastructure to the get the job done. If you did, you would want to handle the Current event on fSFM1. The Form's Current event fires whenever a record is loaded, so that is how you would detect and respond to record navigation.
Cheers,
Mark
 

Users who are viewing this thread

Top Bottom