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 controls primary verb. For example, an unbound object frame could play an embedded sound object. | True (-1) |
No | (Default for unbound object frames) The control cant 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 doesnt allow editing, adding, or deleting data. | True (-1) |
No | (Default for all controls except unbound object frames) The control functions normally and allows editing, adding, and deleting data. | False (0) |
You can set this property in the controls property sheet, a macro, or Visual Basic.
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 controls 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 only to 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 cant have the focus. Data is displayed normally but cant be copied or edited. |
No | No | The control cant have the focus. Control and data are disabled (gray). |
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 on it. Setting the TabStop property to No means that the command button wont 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.
AllowEdits Property, DisplayWhen Property, SetValue Action, TabStop Property, Visible Property (Microsoft Access).
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 IfSub