VBA & Macro Problems

Toggle a Form’s AllowEdits Property with VBA in Microsoft Access

Elise WilliamsElise Williams Nov 25, 2026 869 views

Question details

Use a form button to switch the AllowEdits property between True and False each time it is clicked.

Toggle a Form’s AllowEdits Property with VBA in Microsoft Access
Product
Microsoft Access
Device & OS
not provided
Scenario
A user wants to enable or prevent edits to existing records from a form button.
Observed behavior
Each button click should reverse the form’s current AllowEdits setting.
Before you start

Open the database in Microsoft Access and make sure the form’s record source is updatable. If Access displays a security warning, enable content only if you trust the database so its VBA code can run.

Solution 1Recommended

Use a command button to toggle AllowEdits

Add a standard command button whose Click event reverses the form’s AllowEdits property.

1
Add a command button

Open the form in Design View, then use Design > Button to add a standard command button to the form.

2
Open the Click event

Select the button, open its Property Sheet, and on the Event tab set On Click to [Event Procedure]. Click the ellipsis button to open the VBA editor.

3
Enter the VBA code

Inside the generated Click procedure, enter `Me.AllowEdits = Not Me.AllowEdits`. For a button named Command131, the complete procedure is: Private Sub Command131_Click() Me.AllowEdits = Not Me.AllowEdits End Sub

4
Test the button

Save the form and open it in Form View. Click the button to disable edits to existing records, then click it again to re-enable them.

Use a command button to toggle AllowEdits
Use a standard command button: A toggle button may become unavailable when editing is disabled. You can also update the command button’s Caption in the Click procedure to show the action available next.
Free Microsoft Office alternative

Work with Office files in WPS Office

WPS Office is a free, lightweight alternative for documents, spreadsheets, and presentations. Its familiar interface and support for common Office formats make it easy to move everyday file work to WPS. Microsoft Access databases and their VBA form events still require Access.

Work with tabular data in WPS Spreadsheets.Open and edit common Microsoft Office formats, including XLSX, DOCX, and PPTX.Use a familiar interface for everyday office tasks.Get a free, lightweight office suite.
microsoft office alternative - wps office

Frequently Asked Questions

Why use a command button instead of a toggle button?

A toggle button may become unavailable when the form’s AllowEdits property is False. Use a standard command button with a Click event to switch the property back on.

Why can’t I edit records after setting AllowEdits to True?

The form’s record source must also be updatable. Check the form’s Record Source in its Property Sheet and test the underlying table or query for editability.

Does AllowEdits also prevent new records or deletions?

AllowEdits controls edits to existing records. Use the form’s AllowAdditions and AllowDeletions properties to control adding and deleting records separately.

How can I change the button caption to show the current action?

After toggling AllowEdits in the button’s Click procedure, set the button’s Caption to an appropriate label, such as “Lock editing” when AllowEdits is True and “Enable editing” when it is False.