Enabled Property

Applies To

CheckBox control, ComboBox control, CommandButton control, Frame control, Image control, Label control, ListBox control, MultiPage control, OptionButton control, Page object, ScrollBar control, SpinButton control, Tab object, TabStrip control, TextBox control, ToggleButton control, UserForm object.

Description

Specifies whether a control can receive the focus and respond to user-generated events.

Syntax

object.Enabled [= Boolean]

The Enabled property syntax has these parts:

Part

Description

object

Required. A valid object.

Boolean

Optional. Whether the object can respond to user-generated events.


Settings

The settings for Boolean are:

Value

Description

True

The control can receive the focus and respond to user-generated events, and is accessible through code (default).

False

The user cannot interact with the control by using the mouse, keystrokes, accelerators, or hot keys. The control is generally still accessible through code.


Remarks

Use the Enabled property to enable and disable controls. A disabled control appears dimmed, while an enabled control does not. Also, if a control displays a bitmap, the bitmap is dimmed whenever the control is dimmed. If Enabled is False for an Image, the control does not initiate events but does not appear dimmed.

The Enabled and Locked properties work together to achieve the following effects:

  • If Enabled and Locked are both True, the control can receive focus and appears normally (not dimmed) in the form. The user can copy, but not edit, data in the control.
  • If Enabled is True and Locked is False, the control can receive focus and appears normally in the form. The user can copy and edit data in the control.
  • If Enabled is False and Locked is True, the control cannot receive focus and is dimmed in the form. The user can neither copy nor edit data in the control.
  • If Enabled and Locked are both False, the control cannot receive focus and is dimmed in the form. The user can neither copy nor edit data in the control.
You can combine the settings of the Enabled and the TabStop properties to prevent the user from selecting a command button with TAB, while still allowing the user to click the button. Setting TabStop to False means that the command button won't appear in the tab order. However, if Enabled is True, then the user can still click the command button, as long as TakeFocusOnClick is set to True.

When the user tabs into an enabled MultiPage or TabStrip, the first page or tab in the control receives the focus. If the first page or tab of a MultiPage or TabStrip is disabled, the first enabled page or tab of that control receives the focus. If all pages or tabs of a MultiPage or TabStrip are disabled, the control is disabled and cannot receive the focus.

If a Frame is disabled, all controls it contains are disabled.

Clicking a disabled ListBox does not initiate the Click event.

See Also

Click event, Locked property, TabStop property, TakeFocusOnClick property.

Example

The following example demonstrates the Enabled and Locked properties and how they complement each other. This example exposes each property independently with a CheckBox, so you observe the settings individually and combined. This example also includes a second TextBox so you can copy and paste information between the TextBox controls and verify the activities supported by the settings of these properties.

Note You can copy the selection to the Clipboard using CTRL+C and paste using CTRL+V.

To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:

  • A TextBox named TextBox1.
  • Two CheckBox controls named CheckBox1 and CheckBox2.
  • A second TextBox named TextBox2.
    Private Sub CheckBox1_Change()
        TextBox2.Text = "TextBox2"
        TextBox1.Enabled = CheckBox1.Value
    End Sub
    
    Private Sub CheckBox2_Change()
        TextBox2.Text = "TextBox2"
        TextBox1.Locked = CheckBox2.Value
    End Sub
    
    Private Sub UserForm_Initialize()
        TextBox1.Text = "TextBox1"
        TextBox1.Enabled = True
        TextBox1.Locked = False
        
        CheckBox1.Caption = "Enabled"
        CheckBox1.Value = True
        
        CheckBox2.Caption = "Locked"
        CheckBox2.Value = False
        
        TextBox2.Text = "TextBox2"
    End Sub