Enabled, Locked Properties

Applies To

Enabled property ActiveX control, Bound Object Frame control, Chart control, Check Box control, Combo Box control, Command Button control, List Box control, Option Button control, Option Group control, Page, Subform/Subreport control, Tab control, Text Box control, Toggle Button control, Unbound Object Frame control.

Locked property ActiveX control, Bound Object Frame control, Chart control, Check Box control, Combo Box control, List Box control, Option Button control, Option Group control, Subform/Subreport control, Text Box control, Toggle Button control, Unbound Object Frame control.

Description

  • The Enabled property specifies whether a control can have the focus in Form view.
  • The Locked property specifies whether you can edit data in a control in Form view.
Setting

The Enabled property uses the following settings.

Setting

Description

Visual Basic

Yes

(Default for all controls except unbound object frames) The control can have the focus. If the control is an unbound object frame, double-clicking it executes the control's primary verb. For example, an unbound object frame could play an embedded sound object.

True (–1)

No

(Default for unbound object frames) The control can't have the focus and appears dimmed. If the control is an option group, neither the option group nor the controls inside the option group can have the focus.

False (0)


The Locked property uses the following settings.

Setting

Description

Visual Basic

Yes

(Default for unbound object frames) The control functions normally but doesn't allow editing, adding, or deleting data.

True

No

(Default for all controls except unbound object frames) The control functions normally and allows editing, adding, and deleting data.

False


You can set these properties by using a form's property sheet, a macro, or Visual Basic.

Remarks

Use the Enabled property to enable and disable controls. For example, in Form view you can disable a command button until you have changed data in a text box control. You can then use the control's AfterUpdate event to call an event procedure or macro to enable the command button.

Use the Locked property to protect data in a field by making it read-only. For example, you might want a control to only display information without allowing editing, or you might want to lock a control until a specific condition is met.

You can combine the Enabled and Locked property settings to achieve the following effects.

Enabled

Locked

Effect

Yes

Yes

The control can have the focus. Data is displayed normally and can be copied but not edited.

Yes

No

The control can have the focus. Data is displayed normally and can be copied and edited.

No

Yes

The control can't have the focus. Data is displayed normally but can't be copied or edited.

No

No

The control can't have the focus. Control and data are disabled (dimmed).


The TabStop property can be combined with the Enabled property to prevent the use of the TAB key to select a command button, while still allowing use of the button by clicking it. Setting the TabStop property to No means that the command button won't be in the tab order. However, if the Enabled property is set to Yes, then you can still click the command button.

To allow edits to an embedded or linked object in an unbound object frame, you must set the Enabled property for the unbound object frame to Yes and the Locked property to No.

See Also

AllowEdits property, DisplayWhen property, SetValue action, TabStop property, Visible property.

Example

The following example toggles the Enabled property of a command button and the Enabled and Locked properties of a control, depending on the type of employee displayed in the current record. If the employee is a manager, then the SalaryDetails button is enabled and the PersonalInfo control is unlocked and enabled.

Sub Form_Current()
    If Me!EmployeeType = "Manager" Then
        Me!SalaryDetails.Enabled = True
        Me!PersonalInfo.Enabled = True
        Me!PersonalInfo.Locked = False
    Else
        Me!SalaryDetails.Enabled = False
        Me!PersonalInfo.Enabled = False
        Me!PersonalInfo.Locked = True
    End If
End Sub