Reading Subform data in VBA

  • Thread starter Thread starter =?ISO-8859-1?Q?=22Eoin_C=2E_Bair=E9ad=22?=
  • Start date Start date
?

=?ISO-8859-1?Q?=22Eoin_C=2E_Bair=E9ad=22?=

Hi

In a VBA module, my way of reading data in a subform is to read the main
look-up key from the main form, and then run a query to get the records
that appear in the sub-form, rather than reading the subform directly.

Is there a way of reading the sub-form directly ?

Thanks

Eoin Bairéad
Dublin, Ireland
 
The subform is accessible through the Form property of the *control*
containing the subform. You can't use the name of the subform, you have to
reference it as the form object contained in the Form property:

Set sfrm =
Forms("ParentFormName").Controls("NameOfControl*Containing*Subform").Form

val1 = sfrm.Controls("textbox1")

The examples shown are intentionally verbose. You can use the standard
shortcuts (i.e., Me, Form being the default property of a subform control,
etc.)

Depending on how the control containing the subform was created, it may have
the same name as the form it contains. This doesn't change the fact that the
name of the form is totally useless when trying to set a reference to a
subform. The name of the container control is what matters.
 
Back
Top