name of subform in forms collection

  • Thread starter Thread starter Ian Smith
  • Start date Start date
I

Ian Smith

I need to lock the controls in a form, and I am running
through the controls with:

set frmTemp = Forms(strForm)
For Each ctlTemp in frmTemp.Controls

If I encounter a subform, I want to recursively call my
procedure, but I can't figure out how to express the
subform name.

If my main form as FormMain, and I encounter a control
Child1, with a controlsource of FormSub, what form name do
I pass on? I have tried FormMain.Child1,
FormMain.Child1.Form, and FormSub without success.
 
The subform when opened in the main form isn't a form in its own right. You
have to refer to the main form then treat the subform as a control of the
main form. Your syntax

FormMain.Child1.Form.ControlName
or
Forms!FormMain.Child1.Form.ControlName

would be the way to go, using the main form as the form name.
 
Ian said:
I need to lock the controls in a form, and I am running
through the controls with:

set frmTemp = Forms(strForm)
For Each ctlTemp in frmTemp.Controls

If I encounter a subform, I want to recursively call my
procedure, but I can't figure out how to express the
subform name.

If my main form as FormMain, and I encounter a control
Child1, with a controlsource of FormSub, what form name do
I pass on? I have tried FormMain.Child1,
FormMain.Child1.Form, and FormSub without success.

Instead of your procedure using the form name as its
argument, it could use the form object. Then you would call
the procedure from the main form:

LockAll Me

and the procedure would look more like:

Sub LockAll(frm As Form)
Dim ctlTemp As Control
For Each ctlTemp in frmTemp.Controls
If ctlTemp.ControlType = acSubform Then
LockAll ctlTemp.Form
Else
If ctlTemp.Tag <> "NoLock" _
Then ctlTemp.Lock = True
End If
Next ctl

I'm curious thought, why not just lock the subform control?
 
I can't lock the subform because there's an unbound
control on it that governs what year's data it displays.

If I lock the subform, the unbound control is locked also.
 
Ian said:
I can't lock the subform because there's an unbound
control on it that governs what year's data it displays.

If I lock the subform, the unbound control is locked also.

OK, that makes sense. Thanks for clarifying it.

Did you get the rest of it working?
 
Back
Top