Subform of a subform

H

Hakan Naslund

I have a form with a subform, and that subform contains yet another subform...

In 2003 I could refer to the control count of the most low-level form by
typing:
forms("Mainform").form("Subform1").form("Subform2").controls.count

In 2007, this doesn't work any more... I receive a 2455 error 'invalid
reference to the property Form/Report'

Strange thing is, that getting the form name works:
forms("Mainform").form("Subform1").form("Subform2").name

I need to loop through all controls of subform2 to change labels according
to selected language...
 
M

Marshall Barton

Hakan said:
I have a form with a subform, and that subform contains yet another subform...

In 2003 I could refer to the control count of the most low-level form by
typing:
forms("Mainform").form("Subform1").form("Subform2").controls.count

In 2007, this doesn't work any more... I receive a 2455 error 'invalid
reference to the property Form/Report'

Strange thing is, that getting the form name works:
forms("Mainform").form("Subform1").form("Subform2").name

I need to loop through all controls of subform2 to change labels according
to selected language...


I thought A2003 also required the Form property before the
Controls collection. Try using (my preferred alternate
syntax):

Forms!Mainform.Subform1.Form.Subform2.Form.Controls.Count

In the future, please use Copy/Paste when posting an
expression, VBA code or SQL statement so we don't waste time
discussing typos.

Your reference to the Name property should be returning the
name of the subform *control*, which may or may not be
different from the name of the form object it displays.

To loop through all controls in a form, you do not need to
use the Count property:

With Forms!Mainform.Subform1.Form.Subform2.Form
For Each ctl In .Controls
If ctl.Controls.Count > 0 Then
ctl.Controls(0).Caption = ...
End If
Next ctl
End With
 

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