如何遍历窗体中的所有控件,包括子窗体中的控件 - Access 2007 [英] How to loop through all controls in a form, including controls in a subform - Access 2007
本文介绍了如何遍历窗体中的所有控件,包括子窗体中的控件 - Access 2007的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正如我的问题标题所暗示的,如何遍历表单中的所有控件,包括子表单.
As the title of my question suggest, how is it possible to loop through all the controls in a form, including subforms.
例如我使用下面的子程序来设置带有标签*的控件的背景颜色
For example I use the below sub routine to set the background colour of controls with the tag *
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
如何更改它以捕获子窗体中的控件?在此先感谢您的帮助或指点.
How would alter this to catch the controls in a subform? Thanks in advance for any help or pointers.
干杯诺尔
推荐答案
可以使用递归
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
这篇关于如何遍历窗体中的所有控件,包括子窗体中的控件 - Access 2007的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文