River34
Apr 27 2012, 11:07 AM
I thought that I just posted this question but cannot find it so I'll post again.
On the Open event of a form [frmAvailableHrs], I set properties on the controls of the form's subform [Form3] and it works fine:
Private Sub Form_Open(Cancel As Integer)
Dim ctl As Control
For Each ctl In Forms![frmAvailableHrs]![Form3].Controls
ctl.FontSize = 10
ctl.ColumnWidth = -2
Next
End Sub
I now have a tab subform [sfrmProjectIntakeDetail] that contains it's own subform [Form2] that I need to do the same as above with. I get an error message stating it cannot find the tab subform's subform:
Dim ctl As Control
For Each ctl In Forms![sfrmProjectIntakeDetail]![Form2].Controls
ctl.FontSize = 10
ctl.ColumnWidth = -2
Next
I've also tried adding the mainform name to it with no luck:
For Each ctl In Forms![frmProjectIntake]![sfrmProjectIntakeDetail]![Form2].Controls
ctl.FontSize = 10
ctl.ColumnWidth = -2
Next
Any thoughts on where I went wrong?
Alan_G
Apr 27 2012, 11:10 AM
Hi
Have a look
here for info on how to refer to forms/subforms/sub-subforms
MikeLyons
Apr 27 2012, 11:12 AM
Main forms are accessed through the Forms collection.
Subforms are not, but from your description it sounds like that is what you are trying to do.
A subform is contained in a container control on the form that hosts it, and you access it through the container's Form property.
Forms("formname").SubformContainer.Form.PropertyOrMethod
where formname is the name of your form, SubformContainer is the name of the container control on the form, and PropertyOrMethod is the name of the property or method you are trying to refer to (controls are exposed as properties).
If code is in the host form:
Me.SubformContainer.Form.PropertyOrMethod
Mike
Bob G
Apr 27 2012, 11:37 AM
i am working on something similar I think.
I have a subform where I want to hide certain columns based on the month. I am sure that you could substitute any other control type.
CODE
For Each ctrl In Me.Network_Volumetric_subform.Controls
If ctrl.ControlType = acTextBox Then
If Int(ctrl.tag) <= Month(Now()) Then
ctrl.ColumnHidden = False
Else
ctrl.ColumnHidden = True
End If
Else
End If
Next
River34
Apr 27 2012, 12:49 PM
Still no luck.
Tried to use this on open event for main form:
For Each ctl In Me![sfrmProjectIntakeDetail]![Form2].Controls - ERROR MESSAGE CAN'T FIND Form2
Tried it this way on open event for main form:
For Each ctl In Forms![frmProjectIntake]![sfrmProjectIntakeDetail]![Form2].Controls - ERROR MESSAGE CAN'T FIND form2
Next
Tried this on open event for subform:
For Each ctl In Me![Form2].Controls - ERROR MESSAGE CAN'T FIND sfrmProjectIntakeDetails
I'm just lost at this point. It works if the Form2 is a subform fo the mainform, but not if it is the subform of the mainform's subform.
Jeff B.
Apr 27 2012, 12:58 PM
If you're saying that your [Form2] is a subform IN A SUBFORM, then you'd need to refer to it with something like (untested):
Forms!YourMainForm!YourSubform1Control.Form!Your2ndSubformControl.Form!YourControlIn2ndEmbeddedForm
River34
Apr 30 2012, 10:44 AM
Those typos will get you everytime. This is solved, thanks to all who helped.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please
click here.