0
votes

I build a function to loop through all controls on a form and apply an event if it is a textbox/combobox/listbox, the function also test if the control is a subform and run the same function for the subform controls. The problem I have is if there is another subform in the subform I cannot loop through the controls.

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

If I try the following it works:

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

But this does not, Why?

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

Or is there maybe not a way to do this:

set ctl = Eval("Forms!frmHR_Details!frm_HRDetails2.Form!HRSubForm2.Form!sID")
1
Instead of frm(ctl.Name).Form, try ctl.Form. - Andre
Still does not work - Jp Posthumus
Well, since the subform is not really a form and the function expects a form object to cycle its controls, won't work. - June7

1 Answers

0
votes

Take a look at this link.

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