Referring to Subforms within Subforms

  • Thread starter Thread starter CSDunn
  • Start date Start date
C

CSDunn

Hello,
I usually have to refer to controls on subforms when creating conditions
within macros, and I do this using the following convention:
Forms![main form name]![subform control name].Form![control name]

I now have a situation where I have a subform within a subform, and I need
to refer to a control in the deepest subform. In other words, I need to do
this:
Forms![main form name]![subform control name].Form! [subform control name]
[control name]

I have tried a couple of things to refer to this second subform, but I can't
get anything to work, and I have not been able to find any resources about
how this is done.

Any Ideas?

Thanks!

CSDunn
 
Hi -

Referencing double-nested subforms can appear somewhat
tricky. I'll provide a brief example of the entry you
might make in a macro to retrieve a value from a control
on the 2nd nested subform with a control name of
MyControl, with form & subform names self-explanatory:

=[Forms]![MainForm]![Subform1]![Subform2]![MyControl]

Using VBA within later versions of Access (such as 2002),
those concerned with speed will want to consider using
parentheses and quotes in place of the bang (!) syntax
which is used to separate an object from its collection -
in this case the subform controls and the MyControl
control from their respective Controls collection
(remember - to the parent form, a subform is just another
control). Here's that syntax for the same example:

Forms("MainForm")("Subform1")("Subform2")("MyControl")

This works because the default collection for all forms is
the Controls collection, which is the collection your
subforms as well as your MyControl control within the
Subform2 would be members of. The reason this quoted
syntax is faster is the former bang syntax is translated
to the latter quoted syntax anyways.

I hope this provides the assistance you required for your
project. Please don't hesitate to contact me directly via
e-mail if you need more in-depth help.

Steve Coombes
(e-mail address removed)
Independent Microsoft Access Developer
"Ask me about a fixed-price low cost quote on your
Microsoft Access contracted project today!"
 
Back
Top