如何遍历所有子窗体 MS 访问 VBA



我有一个包含许多子窗体(和子窗体(的主窗体。 我想在我的主子窗体上有一个按钮,它将每个子窗体从启用=真切换到启用=假。是否可以在不专门引用每个子窗体的情况下执行此操作? 也许像这样:对于frmMainForm的每个子形式...?

是的,您可以循环控制:

For Each Control In Me.Controls
    If Control.ControlType = acSubform Then
        ' Do something with this subform control.
    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 使用此方法打开/或当许多子窗体与单个主窗体一起容纳时。

要切换布尔设置,请将其设置为Not自身。我还提供了一种替代方法来检查适用于所有对象的对象类型,而不仅仅是可能具有也可能没有 ControlType 属性的控件。

For Each Control In Me.Controls
    If TypeOf Control Is SubForm Then
        Control.Visible = Not Control.Visible
    End If
Next

最新更新