【问题标题】:How to loop through all subforms MS Access VBA如何遍历所有子窗体 MS Access VBA
【发布时间】:2017-03-23 09:11:32
【问题描述】:

我有一个包含许多子表单(和子子表单)的主表单。我想在我的主子窗体上有一个按钮,它将每个子窗体从启用 = true 切换到启用 = false。是否可以在不必专门引用每个子表单的情况下做到这一点?可能类似于:对于 frmMainForm 的每个子表单...?

【问题讨论】:

    标签: vba ms-access


    【解决方案1】:

    是的,您可以循环控制:

    For Each Control In Me.Controls
        If Control.ControlType = acSubform Then
            ' Do something with this subform control.
        End If
    Next
    

    【讨论】:

      【解决方案2】:
      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 使用此方法打开/或当许多子表单包含在单个主表单中时。

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          猜你喜欢
          • 2013-07-07
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2017-02-23
          • 1970-01-01
          • 2016-07-10
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多