如何遍历表单中的所有控件,包括子窗体中的控件 - Access 2007

noe*_*mcg 10 ms-access ms-access-2007

正如我的问题标题所示,如何循环遍历表单中的所有控件,包括子表单.

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

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
Run Code Online (Sandbox Code Playgroud)

如何改变它以捕获子表单中的控件?提前感谢任何帮助或指示.

干杯诺埃尔

Fio*_*ala 15

你可以使用递归

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
        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
        ElseIf ctl.ControlType = acSubform Then
            colCtrlReq frm(ctl.Name).Form

        End If
Next ctl
Set ctl = Nothing
End Sub
Run Code Online (Sandbox Code Playgroud)