Add VBA Code to an Access Object Frame Click Event
Question details
The user wants to run VBA code when an Access form's picture or unbound object frame is clicked.

- Product
- Microsoft Access
- Device & OS
- not provided
- Scenario
- Assign a Click event procedure to an image or unbound object frame on a form.
- Observed behavior
- The image or object frame cannot be clicked and a test message box does not run.
Open the form in Design View and identify the picture or object frame you want to use. Make sure you can edit the form and that the database is trusted if it contains VBA code.
Assign a VBA procedure to the object frame's Click event
Use the control's property sheet to enable it and create a Click event procedure.
In the Navigation Pane, right-click the form and select Design View.
Click the picture or unbound object frame. If it is difficult to select, open the Property Sheet and choose the control from the selection drop-down at the top.
On the Property Sheet's Data or All tab, set Enabled to Yes so the control can respond to clicks.
On the Event tab, find On Click, select [Event Procedure], and click the ellipsis button (...). If prompted, choose Code Builder.
In the VBA editor, add your code between the generated Sub and End Sub lines. For a simple test, enter MsgBox "Clicked". Save the form, switch to Form View, and click the control.

Assign a macro to the Click event
Use a macro instead of VBA when you want the control to run an Access macro.
Work with Office files in WPS Office
WPS Office is a free, lightweight alternative for documents, spreadsheets, and presentations, with a familiar interface and Microsoft Office format compatibility for an easy transition. Access forms and their VBA Click events still need to be edited in Microsoft Access.

Frequently Asked Questions
Why does clicking my Access object frame do nothing?
In Design View, select the control and check that Enabled is set to Yes. Then verify that its On Click property points to the intended event procedure or macro.
Where do I enter the VBA code for a picture's Click event?
Select the picture in Design View, open the Property Sheet's Event tab, set On Click to [Event Procedure], and click the ellipsis button to open the VBA editor.
Can I use a macro instead of VBA for an object frame?
Yes. In the control's Property Sheet, select a macro in the On Click property or use the ellipsis button to open Macro Builder.
What if the event procedure is assigned but still does not run?
Test the control in Form View and check for an Access security warning. If the database is from a trusted source, enable its content so VBA can run.




