Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I set a control in a subform from the main form (and vice versa)?

How to

How do I set a control in a subform from the main form (and vice versa)?

by  raymondo  Posted    (Edited  )
IÆve seen a few of these type questions floating about so here are a few tips.
LetÆs call our forms myMainFrm and mySubFrm. Trying to use an expression like

Forms!mySubFrm![aControl] = aValue

from myMainFrm wonÆt work because when a mainform-subform is opened, only the main form figures as part of the Forms collection.

The correct syntax is

Forms!myMainFrm!mySubFrm![aControl] = aValue

which can be shortened to

Me!mySubFrm![aControl] = aValue

for procedures attached to myMainFrm. Essentially, the subform is just like any other control on the main form.

When in the subform, it is still only myMainFrm that figures as part of the Forms collection.
ôMeö however, as you would expect, refers to mySubForm.
So, to talk to myMainFrm from mySubFrm the correct syntax is

Forms!myMainFrm![anotherControl] = anotherValue

If the procedure is attached to mySubFrm then you could use ôMeö as follows:

Me.Parent![anotherControl] = anotherValue

I hope this helps.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top