Reference a field in a subform

AnnPhil

Registered User.
Local time
Today, 05:37
Joined
Dec 18, 2001
Messages
246
I have a Main form Called "Company"
Subform called "ContractInfo"
Subform within subform ContractInfo called "ContractDetailsdatasheet" and field name "CourseID"


How do i reference this field? I tried several ways this is one of them.


[Company].[ContractInfo].Form![ContractDetailsdatasheet].Form![CourseID]

Thanks for any help
 
I rarely nest subforms within subforms, but I always fall back onto the explicit naming rules when I need to reference something.

For a control on a subform called ContractInfo on a main form called Company, the "formal" explicit name way to refer is:
Forms("Company").Controls("ContractInfo").Form.Controls(Controlname)

Now, assuming that the control we're after is a subform itself called ContractDetailsdatasheet, and we're trying to get to a control on it called CourseID, I would try:
Forms("Company").Controls("ContractInfo").Form.Controls("ContractDetailsdatasheet").Form.Controls("CourseID")

This can be simplified to:
Forms("Company")("ContractInfo")("ContractDetailsdatasheet")("CourseID")
but I prefer the explicit reference myself.
 
I remember downloading the subs syntax doc from a microsoft site. Maybe msdn?
Anyway.. Here is a helpful Microsoft article
 
Last edited:
Open the Main form in design view and use the Code Builder to drill down to the control on your sub, the correct reference will then be available
 

Users who are viewing this thread

Back
Top Bottom