我有一个主表单和许多子表单(以及子子表单)。我想在我的主子表单上放置一个按钮,可以将每个子表单从enabled=true切换到enabled=false。是否可能在不必具体引用每个子表单的情况下实现这一点?也许像这样:对于frmMainForm的每个子表单...
是的,您可以循环控件:
For Each Control In Me.Controls
If Control.ControlType = acSubform Then
' Do something with this subform control.
End If
Next
要切换布尔设置,您可以将其设置为Not
本身。我还提供了一种替代方法,可检查所有对象的类型,而不仅仅是可能具有ControlType
属性的控件。
For Each Control In Me.Controls
If TypeOf Control Is SubForm Then
Control.Visible = Not Control.Visible
End If
Next
For Each Control In Me.Controls
If Control.ControlType = acSubform Then
If Control.Name = sSubform Then
Control.Visible = True
Else
Control.Visible = False
End If
End If
Next
help4access.com使用此方法在一个主表单中承载多个子表单时打开/关闭它们。