Applies ToAccess for Microsoft 365 Access 2024 Access 2021 Access 2019 Access 2016

Applies to

BoundObjectFrame Object

OptionButton Object

CheckBox Object

OptionGroup Object

ComboBox Object

SubForm Object

CustomControl Object

TextBox Object

ListBox Object

ToggleButton Object

ObjectFrame Object

The Locked property specifies whether you can edit data in a control in Form view. Read/write Boolean.

expression.Locked

expression Required. An expression that returns one of the objects in the Applies To list.

Remarks

The Locked property uses the following settings.

Setting

Visual Basic

Description

Yes

True

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

No

False

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

You can set these properties by using a form's property sheet, a macro, or Visual Basic for Applications (VBA) code.

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.

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, 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 IfEnd Sub

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.