Referring to Subforms within Subforms

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
 
S

Steve Coombes

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!"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top