Others

Add VBA Code to an Access Object Frame Click Event

Ayan MasoodAyan Masood Nov 20, 2026 869 views

Question details

The user wants to run VBA code when an Access form's picture or unbound object frame is clicked.

Add VBA Code to an Access Object Frame Click Event
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the form in Design View

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

2
Select the control

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.

3
Enable the control

On the Property Sheet's Data or All tab, set Enabled to Yes so the control can respond to clicks.

4
Create the Click procedure

On the Event tab, find On Click, select [Event Procedure], and click the ellipsis button (...). If prompted, choose Code Builder.

5
Add and test the code

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 VBA procedure to the object frame's Click event
Check database trust: If the procedure still does not run, check for an Access security warning and enable content only if you trust the database.
Free Microsoft Office alternative

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.

Use a familiar interface to work with Office filesOpen and edit common Microsoft Office formats, including DOCX, XLSX, and PPTXWork with documents, spreadsheets, and presentations in one lightweight suiteKeep Access-specific object frame and VBA edits in Microsoft Access
microsoft office alternative - wps office

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.