How to Lock a text box on an Access form / How to unlock a text box on an Access Form

APPLIES TO: ACCESS 2007, 2010 (UNTESTED IN EARLIER VERSIONS)

The following tutorial shows you how you can use VBA to lock or unlock a text box on an access form following the update of another text box or after the click of a button.

For this tutorial you will need to create the following fields /controls on your form:

A text box called “textbox1” (the box that will be updated)

A text box called “textbox2” (the box that will be locked)

A command button Called “btnLocked”

1. Select the text box called “textbox1”

2. In the tools section of the “Design” tab click on the item called “Property Sheet” and select the “Event” tab

3. On the “After Update” property click on the little black down arrow / triangle and select “Event Procedure”

4. Click on the three dots next to the little black down arrow / triangle – this will open up the VBA window and you should see the following:

Private Sub textbox1_AfterUpdate()

End Sub

5. On a new line directly between the two lines above add the following

Me.textbox2.locked = True

6. Go back to your form and select the command button called “btnLocked”

7. In the tools section of the “Design” tab click on the item called “Property Sheet” and select the “Event” tab

8. On the “On Click” property click on the little black down arrow / triangle and select “Event Procedure”

9. Click on the three dots next to the little black down arrow / triangle – this will open up the VBA window and you should see the following:

Private Sub btnLocked_Click()

End Sub

10. On a new line directly between the two lines above add the following

Me.textbox2.Locked = False

Save your changes and test your form / report

Note: The second text box will only be locked once the user has finished entering data and clicked away from the field.