Click Event — Event Procedures Example

In the following example, the Click event procedure is attached to the ReadOnly check box. The event procedure sets the Enabled and Locked properties of another control on the form, the Amount text box. When the check box is clicked, the event procedure checks whether the check box is being selected or cleared and then sets the text box's properties to enable or disable editing accordingly.

To try the example, add the following event procedure to a form that contains a check box called ReadOnly and a text box named Amount.

Private Sub ReadOnly_Click()
    With Me!Amount
        If Me!ReadOnly = True Then        ' If checked.
            .Enabled = False                ' Disable editing.
            .Locked = True
        Else                                    ' If cleared.
            .Enabled = True                ' Enable editing.
            .Locked = False
        End If
    End With
End Sub