Microsoft Office Tutorials and References
In Depth Information
Running Macros in Forms
as the order displayed on the Orders form, you type this value in the Where
Condition argument of the OpenReport action:
[OrderID] = [Forms]![Orders]![OrderID]
The first OrderID field is the one in the record source of the report; the
second one is the OrderID field on the form.
The next section, “Printing matching records from a form,” shows you how
to make a button on your form that uses this condition to print a report
containing only records that match the record displayed on the form.
In the Where Condition argument of many actions (an argument that you
use to filter records), you must always use this longer version of the name of
the control that you want to refer to. If you don’t, Access won’t know what to
do and will display an annoying error message.
Printing matching records from a form
Now you know everything that you need to know to create a useful command
button: a button that prints a report for the record displayed in the form.
An order form may have a button to print a mailing label, a button to print a
packing slip, and a button to print an invoice (if not paid) or receipt (if paid),
all filtered to include only the order that’s currently displayed on the form.
Store these button macros as submacros in a macro for the form (such as
the Order Form macro).
The PrintInvoiceOrReceipt submacro, shown in Figure 2-5, saves any
changes made in the current record on the form and then prints the invoice
for the current record. For each macro, you create a button that calls the
macro via the button’s On Click property. Figure 2-6 shows a form in
Design view, with the property sheet for the Print Invoice/Receipt
command button.
Figure 2-5:
A macro
that prints
a report
containing
only records
for the order
currently
displayed on
the form.
Search JabSto ::




Custom Search