VBA & Macro Problems

Make an Access 2013 Form Button Run VBA Code

Elise WilliamsElise Williams Nov 27, 2026 870 views

Question details

The user wants a command button on an Access 2013 form to run VBA code when clicked.

How to Make an Access 2013 Form Button Run VBA Code
Product
Microsoft Access 2013
Device & OS
not provided
Scenario
Configure a form command button to trigger a VBA procedure.
Observed behavior
Clicking the configured button should run the code assigned to its On Click event.
Before you start

Open the database and identify the form and button you want to use. If Access displays a security warning, enable content only if you trust the database, because disabled code will not run.

Solution 1Recommended

Assign VBA code to the button's On Click event

Use the form's Design view and Code Builder to create or edit the button's click event procedure.

1
Open the form in Design view

In the Navigation Pane, right-click the form and select Design View.

2
Select or add a button

Select an existing command button, or choose Command Button from the Controls group on the Design tab and draw it on the form. Cancel the wizard if it opens.

3
Open the click event

Select the button and open its Property Sheet. On the Event tab, find On Click and click the ellipsis button next to the property.

4
Enter the VBA code

Choose Code Builder. In the VBA editor, enter your code between the generated Private Sub and End Sub lines. For a simple test, enter MsgBox "Button clicked".

5
Save and test the button

Save the code and form, switch to Form View, and click the button. Confirm that the On Click property shows [Event Procedure] if the code does not run.

Assign VBA code to the button's On Click event
Use trusted code: Access may block VBA in an untrusted database. Enable content only when you trust the file and its source.
Free Microsoft Office alternative

Use WPS Office for Everyday Office Documents

WPS Office is a free, lightweight alternative for working with documents, spreadsheets, and presentations in a familiar interface. Open common Microsoft Office formats to make migration easier. WPS Office does not replace Access or run Access form VBA code.

Edit documents and spreadsheets in a familiar interfaceOpen and save common Microsoft Office formats, including DOCX, XLSX, and PPTXUse spreadsheets for tabular work alongside an Access database workflowGet started with a free, lightweight office suite
QA img-9

Frequently Asked Questions

Where is the On Click property for an Access button?

Open the form in Design View, select the button, and open its Property Sheet. The On Click property is on the Event tab.

What should the On Click property show for VBA code?

It should show [Event Procedure]. Click the ellipsis beside On Click and choose Code Builder to open the associated procedure.

Why does nothing happen when I click the button?

Check that the form is in Form View and that the button's On Click property is set to [Event Procedure]. Access may also block VBA if the database is not trusted; enable content only if you trust the file.

Can a corrupt database cause a button to behave incorrectly?

It can be a possible cause. Create a blank database, import the form and its dependencies through External Data > Access, and test the button there. A different result does not by itself prove corruption.

Can WPS Office run an Access form's VBA code?

No. Use Microsoft Access to edit and run Access form event procedures. WPS Office is an alternative for documents, spreadsheets, and presentations, not Access databases.