Syntax for Referring to a subform

R

Renraf

If I have this layout in a form:

InputStudyData (primary form)
-[Primary Tasks Form] (subform)
--Category (control)
--Interruptions (subform)

How do I refer to the Category control on the Primary Tasks Form?

Is it

Forms!InputStudyData![Primary Tasks Form].Category
Forms!InputStudyData.[Primary Tasks Form].Category
Forms![Primary Tasks Form].Category
or something else entirely?

Not sure if I should refer to the subform as a control on the parent form or
as its own form, and when I am supposed to use <!> versus <.>

Thanks.
 
R

Renraf

Sorry, should have done a more thorough search before asking. I believe this
is the correct syntax?

Forms!InputStudyData![Primary Tasks Form].Form!Category
 
J

John W. Vinson

Sorry, should have done a more thorough search before asking. I believe this
is the correct syntax?

Forms!InputStudyData![Primary Tasks Form].Form!Category

Yes... with one caveat.

A Subform Control is a box on the mainform, designed to contain a Form object
(its Source Object property specifies which form is used).

The form object within the Subform control is a different kind of object.

The name *of the Subform Control* - the box on the mainform - is what you need
to use in the syntax above: in your case [Primary Tasks Form]. This name may
or may not be the same as the Name property of the Source Object Form within
the control; the actual name of the form you're using is irrelevant, only the
name of the Subform Control is used.
 
R

Renraf

Thank you, Douglas, for the resource, and thank you, Sylvain, for the detail
of your response.

Sylvain Lafontaine said:
The Bang (!) operator is for collections of elements that are dynamically
created such as the various controls on your form while the Dot operator is
for static properties such as the height or width of the form. Usually, if
you use the wrong operator, Access will search for the other possibilities
so it's not a big deal. However, in some cases, it can make a big change if
an identifiant can be seen both as a standard property or as a member of a
collection. To that, I should add that each object can have a default
collection.

For your subform problem, you must access it by using the name of the
control that host the subform followed by the standard property Form:

Forms!InputStudyData![NameOfTheControl containing the Primary Tasks
Form].Form!Category

--
Sylvain Lafontaine, ing.
MVP - Windows Live Platform
Email: sylvain2009 sylvainlafontaine com (fill the blanks, no spam please)
Independent consultant and remote programming for Access and SQL-Server
(French)


Renraf said:
If I have this layout in a form:

InputStudyData (primary form)
-[Primary Tasks Form] (subform)
--Category (control)
--Interruptions (subform)

How do I refer to the Category control on the Primary Tasks Form?

Is it

Forms!InputStudyData![Primary Tasks Form].Category
Forms!InputStudyData.[Primary Tasks Form].Category
Forms![Primary Tasks Form].Category
or something else entirely?

Not sure if I should refer to the subform as a control on the parent form
or
as its own form, and when I am supposed to use <!> versus <.>

Thanks.


.
 

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