Referring Controls

  • Thread starter Thread starter Robert Neville
  • Start date Start date
R

Robert Neville

Referencing controls on a form object has always confused me. Even
though MS Access add to the confusion since implicit and explicit
approaches exist. In addition, one has to decide where to bang or not
(no pun intend).

Please let me know the different methods involved in referencing
controls on a sub-form, which itself is on a tab control.

Form -> frmComp
TabControl -> tabctlComp
Sub-form -> sfrmCompAddr
Control -> cboAddr1

My aim here involves determining whether the control, sub-form, or
form have been change. Presently, I plan on testing on the dirty
property; and may pass old values to variables. Let me know if you
familiar with this objective.
 
Hi Robert,

It is confusing! I won't attempt to go into the issue regarding the bang
(but you can easily find my opinions if you search google on Bang vs. Dot).

To refer to a control on a subform you need to know the name of the subform
control - this is the container through which the form object named in the
SourceObject property of the subform control is viewed. The subform control
might or might not have the same name as the sourceobject form and this is
one of the things that causes confusion. To be sure, open main form, click
once on the subform to select the subform control and then look at the Name
propert under the Other tab of the property sheet - this is the name of the
subform control.

Now, to reference the control, use the following pattern where sfrmMySubForm
is the name of the subform control:

me.sfrmMySubForm.form.cboAddr1

This takes you to the control named cboAddr1 on the form object of the
subform.

Note that the tabControl is irrelevant in forming the control reference.

Clear as mud? :-)


Thanks for your insightful reply. Please let me know if I have listed
all the possibilities for a control on a sub-form. First, the actual
object names follow.

Form -> frmComp
TabControl -> tabctlComp
Sub-form -> sfrmCompAddr
Control -> cboAddr1

Now, here is a list of control references to cboAddr1; let me know if
I am doing right (from the code behind sfrmCompAddr). I am looking for
all possible variations (maybe this info will help return how to do
this).

Me!sfrmCompAddr!cboAddr
Me.Controls("sfrmCompAddr").Controls("cboAddr1")
Me!Controls.sfrmCompAddr!cboAddr1
Me!Controls.sfrmCompAddr.Controls.cboAddr1
Forms!frmComp.Controls!txtCompName
Forms!frmComp.Form!sfrmCompAddr!cboAddr1
Forms!frmComp.Controls!sfrmCompAddr.Controls!cdoAddr1
Forms!frmComp.Controls!tabctlComp!Controls!sfrmCompAddr.Controls!cboAddr1
 
Back
Top