Microsoft Office Tutorials and References
In Depth Information
Running Macros in Forms
4. If you’re attaching a macro to a control (such as a command button),
click that control.
5. To attach the macro to the form itself, click the box where the rulers
intersect in the top-left corner of the form.
Now the property sheet shows the available events for the control or for
the form itself.
6. Click the event property that you want to use.
If you’re attaching a macro to a command button, for example, click the
On Click property to run the macro when the user clicks the command
button. If you want the macro to run whenever you insert a record by
using the form, click the Before Insert property.
Book VI
Chapter 2
7. Click the down arrow at the right end of the property, and choose the
name of the macro from the drop-down menu.
Access lists all the macros and submacros in alphabetical order. If the
Order Form macro contains a macro named AddRecord, for example,
choose Order Form.AddRecord. If none of the existing macros is
appropriate for your purpose, you can create an event procedure
instead, writing it in the form of a VBA subroutine.
See Book VIII, Chapter 1 for a detailed description of VBA.
Most controls have several events to which you can assign a macro,
including when your cursor enters and exits the control, when you click or
doubleclick it, or when its value changes. Figure 2-3 shows the Event tab of the
property sheet for a command-button control, with a macro name in the On
Click event property.
Figure 2-3:
The Event
properties
of a
commandbutton
control on a
form.
Table 2-2 shows the events that most commonly occur for controls on a
form.
Search JabSto ::




Custom Search