Others

Add a Button to Run an Update Query in Microsoft Access

John WilsonJohn Wilson Nov 25, 2026 868 views

Question details

Add a command button to an Access form so users can run an update query without opening the database design environment.

Add a Button to Run an Update Query in Microsoft Access
Product
Microsoft Access
Device & OS
not provided
Scenario
Users need to find values and run an update query from a form, optionally entering a replacement value.
Observed behavior
The desired result is a form button that runs the query and safely restores Access warnings if an error occurs.
Before you start

Create and test the update query on a copy of the data, and note its exact name in the Navigation Pane. Make sure the database is trusted so its VBA code can run.

Solution 1Recommended

Run the update query from a form button

Use the button’s On Click event to confirm the action, run the saved query, and restore warnings even if the query fails.

1
Add a command button

Open the form in Design View, choose Button from the Design tab’s Controls group, and place it on the form. If the Command Button Wizard opens, cancel it.

2
Open the click event

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

3
Add the query code

Inside the generated Click procedure, add the following code, replacing qryUpdate with the exact name of your saved update query: On Error GoTo ErrHandler If MsgBox("Run this update?", vbYesNo + vbQuestion, "Confirm update") <> vbYes Then Exit Sub DoCmd.SetWarnings False DoCmd.OpenQuery "qryUpdate" CleanUp: DoCmd.SetWarnings True Exit Sub ErrHandler: MsgBox "The update could not be completed: " & Err.Description, vbExclamation Resume CleanUp

4
Save and test the button

Save the form and VBA code, switch to Form View, and select the button. Confirm the action and check that the intended records changed.

Run the update query from a form button
Warnings and confirmation: SetWarnings False suppresses Access action-query warnings. The code supplies its own confirmation and restores warnings on both the normal and error paths.
Free Microsoft Office alternative

Work with Office Documents and Spreadsheets in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface and Microsoft Office format compatibility for an easier move between applications. It does not run Access forms, update queries, or Access VBA.

Use WPS Spreadsheets to review and edit tabular data.Open and save Microsoft Excel XLSX, Word DOCX, and PowerPoint PPTX files.Navigate documents with a familiar, easy-to-use interface.Work with a lightweight office suite available for free.
QA img-9

Frequently Asked Questions

Where do I put the code for the Access button?

In the form’s Design View, select the button, open the Property Sheet, and choose [Event Procedure] for On Click on the Event tab. Select the ellipsis button to edit the generated VBA procedure.

How can I find records before entering a replacement value?

Enter the search value in a form text box and open a separate select query whose Criteria references that control, such as Forms![frmUpdate]![txtFind]. Review the results, then enter the replacement value and run the update query.

Why should the code restore Access warnings?

DoCmd.SetWarnings False suppresses action-query warnings beyond the immediate query. Use an error handler that returns to cleanup code containing DoCmd.SetWarnings True so warnings are restored if the query fails.

Why does the button do nothing when I click it?

Check that On Click is set to [Event Procedure], the query name in DoCmd.OpenQuery matches the saved query, and the database is trusted so VBA can run.