子窗体内的子窗体控件

时间:2017-10-19 10:38:17

标签: vba loops ms-access subforms

我构建了一个循环遍历窗体上所有控件的函数,如果它是一个文本框/组合框/列表框,则应用一个事件,该函数还测试该控件是否为子窗体并为子窗体控件运行相同的函数。我遇到的问题是如果子窗体中有另一个子窗体我无法遍历控件。

Public Function FE_LoopThroughAllControlsNumLockOn(frm As Form)
Dim ctl As control
For Each ctl In frm
    If ctl.ControlType = acSubform Then
        Call FE_LoopThroughAllControlsNumLockOn(frm(ctl.Name).Form) 'Error here on subform within subform
    ElseIf xIsControlForEventNumLock(ctl.ControlType) = True Then
        ctl.OnGotFocus = "=FM_NUM_ON()"
    End If
Next ctl
Set ctl = Nothing
End Function

Function xIsControlForEventNumLock(vControlType As AcControlType) As Boolean
    Select Case vControlType
        Case Is = acComboBox: xIsControlForEventNumLock = True
        Case Is = acListBox: xIsControlForEventNumLock = True
        Case Is = acTextBox: xIsControlForEventNumLock = True
        Case Else: xIsControlForEventNumLock = False
    End Select
End Function

如果我尝试以下方法就可以了:

Debug.Print Forms!frmHR_Details!frm_HRDetails2.Form!HRSubForm2.Form!sID

但这不,为什么?

Debug.Print Forms("frmHR_Details").Form("frm_HRDetails2").Form.Form("HRSubForm2").Form.sID.Value

或者可能没有办法做到这一点:

set ctl = Eval("Forms!frmHR_Details!frm_HRDetails2.Form!HRSubForm2.Form!sID")

1 个答案:

答案 0 :(得分:0)

看一下这个链接。

http://access.mvps.org/access/forms/frm0031.htm

To refer to a control property, like Enabled         
On Mainform     
Me!ControlName.Enabled  Me.Parent!ControlName.Enabled
On Sub 1                Me!Subform1.Form!ControlName.Enabled    Me!ControlName.Enabled
On Sub 2                Me!Subform1.Form!Subform2.Form!ControlName.Enabled  Me!Subform2.Form!ControlName.Enabled