Link to home
Start Free TrialLog in
Avatar of bill201
bill201

asked on

problem with a formula to close all controls in a form in microsoft access 2010

my code is


but i get a compile error because vba don't recognize the  "controltype"
If Me.Closed = True Then
    Dim Ctrl As Controls
    For Each Ctrl In Me.Controls
       If Ctrl.ControlType = acTextBox Or Ctrl.ControlType = acCheckBox Or Ctrl.ControlType = acComboBox Or Ctrl.ControlType = acSubform Then
            Ctrl.Locked = True
        End If
    Next Ctrl
Else
    Dim Ctrl As Controls
    For Each Ctrl In Me.Controls
       If Ctrl = acTextBox Or Ctrl.ControlType = acCheckBox Or Ctrl.ControlType = acComboBox Or Ctrl.ControlType = acSubform Then
            Ctrl.Locked = True
        End If
    Next Ctrl
End If

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of JVWC
JVWC
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And I suspect it can all be shortened to:

    Dim Ctrl As Control

    For Each Ctrl In Me.Controls
        If Ctrl.ControlType = acTextBox Or Ctrl.ControlType = acCheckBox Or Ctrl.ControlType = acComboBox Or Ctrl.ControlType = acSubform Then
            Ctrl.Locked = (Me.Closed = True) ' or (Not Me.Closed = True)
        End If
    Next Ctrl