Control Object

Description

The Control object represents a control on a form or report.

Remarks

All controls on a form or report belong to the Controls collection for that Form or Report object. When you refer to an individual Control object in the Controls collection, you can refer to the Controls collection either implicitly or explicitly.


Me!NewData                    ' Implicitly refer to Controls collection.


Me![New Data]                ' Use if control name contains space.


Me("NewData")                ' Performance slightly slower.
(0)                        ' Refer to control's index in collection.


Me.Controls!NewData            ' Explicitly refer to Controls collection.
.Controls[New Data]
.Controls("NewData")
.Controls(0)

Note You can use the Me keyword to represent a form or report within code only if you’re referring to the form or report from code within the form module or report module. If you’re referring to a form or report from a standard module or a different form or report’s module, you must use the full reference to the form or report.

Each Control object is denoted by a particular intrinsic constant. For example, the intrinsic constant acTextBox is associated with a text box control, and acCommandButton is associated with a command button. To determine the type of an existing control, use the ControlType property. However, you don’t need to know the specific type of a control in order to use it in code. You can simply represent it with a variable of data type Control. You can see these constants in the Object Browser by clicking Modules on the Modules/Classes list, and then looking up the constants in the Methods/Properties list.

Properties

ControlType Property.

See Also

Controls Collection; CreateControl, CreateReportControl Functions; Form Object; Me; Report Object.

Example

The following example enumerates all controls in the Controls collection of a form called OrderForm and sets certain properties if the control is a text box.


Sub SetTextBoxProperties()


    Dim frm As Form, ctl As Control

    Set frm = Forms!OrderForm
    ' 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 ctlSub