Share via


Event Properties

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

                 

Event properties cause a macro or the associated Visual Basic event procedure to run when a particular event occurs. For example, if you enter the name of a macro in a command button's OnClick property, that macro runs when the command button is clicked. For a complete list of event properties, see Events and Event Properties Reference.

Setting

To run a macro, enter the name of the macro. You can choose an existing macro in the list. If the macro is in a macro group, it will be listed under the macro group name, as macrogroupname.macroname.

To run the event procedure associated with the event, select [Event Procedure] in the list.

Note   Although using an event procedure is the recommended method for running Visual Basic code in response to an event, you can also run a user-defined function when an event occurs. To run a user-defined function, place an equal sign (=) before the function name and parentheses after it, as in =functionname( ).

You can set event properties in the property sheet for an object, in a macro, or by using . Note that you can't set any event properties while you're formatting or printing a form or report.

Tip   You can use builders to help you set an event property. To use them, click the Build button to the right of the property box, or right-click the property box and then click Build on the shortcut menu. In the Choose Builder dialog box, select:

  • The Macro Builder to create and specify a macro for this event property. You can also use the Macro Builder to edit a macro already specified by the property.

  • The Code Builder to create and specify an event procedure for this event property. You can also use the Code Builder to edit an event procedure already specified by the property.

  • In a Microsoft Access database (.mdb), the to choose and specify a user-defined function for this event property.

In Visual Basic, set the property to a string expression.

To run this Use this syntax Example
Macro "macroname"
Button1.OnClick = "MyMacro"
Event procedure "[Event Procedure]"
Button1.OnClick = "[Event Procedure]"
User-defined function "=functionname( )"
Button1.OnClick = "=MyFunction()"