如何循环浏览表单中的所有控件,包括子表单中的控件-Access 2007

问题描述 投票:10回答:2

正如我的问题的标题所暗示的,如何遍历表单(包括子表单)中的所有控件。

例如,我使用下面的子例程来设置带有标签*的控件的背景颜色

Public Sub colCtrlReq(frm As Form)
'  Sets background color for required field -> Tag = *
Dim setColour As String
setColour = RGB(255, 244, 164)
Dim ctl As Control
For Each ctl In frm.Controls
        If ctl.ControlType = acTextBox Or ctl.ControlType = acComboBox Or ctl.ControlType = acListBox Then
            If InStr(1, ctl.Tag, "*") <> 0 Then
                ctl.BackColor = setColour
            End If
        End If
Next ctl
Set ctl = Nothing
End Sub

如何改变它以捕获子窗体中的控件?在此先感谢您的帮助或指点。

欢呼Noel

vba ms-access ms-access-2007
2个回答
15
投票

2
投票
© www.soinside.com 2019 - 2024. All rights reserved.