How to use the forms-collection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,
I have a problem using the forms collection in vb.
I have statement like this
myvalue = Forms(str1).Controls(str2).Value
where str1 is a formname of a loaded form and str2 is the name of a control
on that form.
Let say
str1 = "Myform"
str2 = "Mycontrol"
after executing it Myvalue is correctly retrieved from the form.

But now my problem:
when str1 holds the name of a subform Forms(str1) fails because the subform
is not in the forms collection.

Does anyone know how to access the subform?

Thanks for any help
 
Remember that all that exists on the parent form is a Subform control that
happens to hold a form being used as a subform.

To reference a control on the form that's being used as a subform, try:

myvalue =
Forms("Form1").Controls("SubformControl").Form.Controls("ControlOnSubform")

Note that the name of the Subform control may or may not be the same as the
name of the form being used as the subform. It depends on how the subform
control was added to the parent form.

You may find http://www.mvps.org/access/forms/frm0031.htm at "The Access
Web" a useful reference.
 
Back
Top