我构建了一个函数来循环遍历表单上的所有控件,如果它是文本框/组合框/列表框,则应用事件,该函数还测试控件是否是子表单并为子表单控件运行相同的函数。我遇到的问题是,如果子表单中有另一个子表单,我将无法遍历控件。
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")