Control Object, Controls Collection Example

The following example enumerates all the controls in the Controls collection of a form. The procedure is called from a form module and the Me keyword is used to pass the Form object to the procedure. The procedure sets certain properties if the control is a text box.

' Call SetTextBoxProperties procedure.
SetTextBoxProperties Me

Sub SetTextBoxProperties(frm As Form)
    Dim ctl As Control

    ' Enumerate Controls collection.
    For Each ctl In frm.Controls
        ' Check to see if control is text box.
        If ctl.ControlType = acTextBox Then
            ' Set control properties.
            With ctl
                .SetFocus
                .Enabled = True
                .Height = 400
                .SpecialEffect = 0
            End With
        End If
    Next ctl
End Sub