How do I refer to a control in a subform, nested in another subform?

pityocamptes

Registered User.
Local time
Yesterday, 23:03
Joined
Dec 8, 2010
Messages
27
I basically have a main form (A), with a subform (B) on the main form. I also have a subform (C) nested inside subform (B). How do I access a control in subform (C)??? I have tried all sorts of combinations and I keep getting VB errors in Access. Any help appreciated. Thanks!!!
 
You might want to read this from my website.

Also, there are a few different ways to do this but I have found this to be the easiest to remember (especially for nested subforms):
Code:
Forms("YourMainFormNameHere").Controls("YourSubformControlHere").Form.Controls("YourSecondSubformnameHere").Form.Controls("YourControlOnSecondSubform).Value
And YourSubformControlHere means the name of the subform Control which HOUSES the subform on the main form or on the other subform. Not the name of the subform itself unless both are named exactly the same (subform and subform control).
 
You might want to read this from my website.

Also, there are a few different ways to do this but I have found this to be the easiest to remember (especially for nested subforms):
Code:
Forms("YourMainFormNameHere").Controls("YourSubformControlHere").Form.Controls("YourSecondSubformnameHere").Form.Controls("YourControlOnSecondSubform).Value
And YourSubformControlHere means the name of the subform Control which HOUSES the subform on the main form or on the other subform. Not the name of the subform itself unless both are named exactly the same (subform and subform control).


Thanks! I will try this. Do I use the () and "" in the code? ("YourSecondSubformnameHere").
 
For some reason this is not working. It keeps saying it can't find the subform. Perhaps I am mistaken in the nesting, though I do not think so. How would I know for sure? Thanks!
 
For some reason this is not working. It keeps saying it can't find the subform. Perhaps I am mistaken in the nesting, though I do not think so. How would I know for sure? Thanks!
Read the article I posted and look at the screenshot in the article. It should help you figure it out. Post back if it doesn't but first try.
 
The OP has specified the destination quite clearly but has not stated the starting point.

Chris.
 
Ok, here is a little trick that works quite well.

Open the form that contains the nested forms in design view.
Now create a new blank query. No need to add any tables.
Now go to the field and select Build wizard.
In the Expression Builder select Forms then Loaded Forms.
Keep drilling down untill you find the field you with to refer to ans select it.
You now have the correct syntex for that field.
 
...
Now create a new blank query. No need to add any tables.
Now go to the field and select Build wizard.
...
Or a blank form with a textbox.
Go to the Control Source of the textbox and click the elipsis button, select Expression Builder and OK that.
 
Ok, here is a little trick that works quite well.

Open the form that contains the nested forms in design view.
Now create a new blank query. No need to add any tables.
Now go to the field and select Build wizard.
In the Expression Builder select Forms then Loaded Forms.
Keep drilling down untill you find the field you with to refer to ans select it.
You now have the correct syntex for that field.

Here's the same explanation but with pictures.
 

Users who are viewing this thread

Back
Top Bottom