Make an Access 2013 Form Button Run VBA Code
Question details
The user wants a command button on an Access 2013 form to run VBA code when clicked.

- 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.
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.
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.
In the Navigation Pane, right-click the form and select Design View.
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.
Select the button and open its Property Sheet. On the Event tab, find On Click and click the ellipsis button next to the property.
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".
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.

Test the form in a new Access database
Use this check if the button or form still behaves unexpectedly after its event is configured.
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.

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.




