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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Referencing a subform within a subform

Status
Not open for further replies.

primagic

IS-IT--Management
Jul 24, 2008
476
GB
Hi,

I have a query which has some criteria refering to a control on a form.

Such as Forms!frmMain!Control

However,

The form with the control on it, will be a subform of another subform so it will be:

Forms!frmMain!SubForm!SubForm!Control.

However, when i open the mainform, its popping up with the parameter box as if it cant find the field.

How do I reference a control on a subform within a subform.

I have tried this link:
But don't really understand it. I am sure the answer is there and I have tried lots of examples and none of them seem to work.

Any help please would be appreciated

Thank you
 
You need to construct the reference so that it contains the name of the subform control and then the form object. The name of the subform control is not always the same as the form contained.

The reference would be something like:

Code:
Me.[NameOfMySubformControl].Form.MyControl

Where Me is short for Forms!MyForm when the code is in the module belonging to the form, in other words, Me=ThisForm.

Now to go down a level:

Code:
Me.[NameOfMySubformControl].Form.[NameofMySubformControl].Form.Mycontrol

You do not need the square brackets if there are no spaces in your control names and you have avoided reserved words.


 
@dhookom The OP already cited the MVPs document and said "But don't really understand it. I am sure the answer is there and I have tried lots of examples and none of them seem to work."

 
Thanks for the clarification. I guess my reply was more of a reaction to primagic's "query which has some criteria refering to a control on a form" and your reply with "Me.". You would never use "Me." anywhere other than code. It would not be used in a query criteria.

Since primagic never provided actual form, subform control, and control names, we can't be of much greater assistance than pointing to some generic syntax examples.

Duane
Hook'D on Access
MS Access MVP
 
Thank you for your replies.

When I said I refered to that website, I am sure I have tried all the combinations I thought would work and I couldnt get any of them to work. I am obviously doing something wrong because I am sure that website has the correct code. That is what I mean.

My code at the moment is:

Code:
Between [Forms]![frmMain_expandlg].[Dashboard].[Form].[frmHowHeardSubGraph].[Form].[StartDate] And [Forms]![frmMain_expandlg].[Dashboard].[Form].[frmHowHeardSubGraph].[Form].[EndDate]

So frmMain_expandlg is the parent form, dashboard is the first subform, frmHowHeardSubGraph is the second subform and the controls are startdate and enddate

Thank you
 
Code:
Between [Forms]![frmMain_expandlg]![Dashboard].[Form]![frmHowHeardSubGraph].[Form]![StartDate] And [Forms]![frmMain_expandlg]![Dashboard].[Form]![frmHowHeardSubGraph].[Form]![EndDate]
This all assumes you understand the difference between the name of the subform control and the source object. They are typically but not always the same.

Have you attempted to use the expression builder?

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top