Microsoft Access 2010 Bible

(Rick Simeone) #1

Part IV: Professional Database Development


1068


FIGURE 30.14

mcrReportMenuEnhanced uses temporary variables to open the report in Print or Print Preview view.


The first two SetTempVar actions in mcrReportMenuEnhanced set the values of the tempo-
rary variables — ReportName and ReportView — from cboReport and fraView on frm-
ReportMenuEnhanced. The OpenReport actions use the temporary variables in the Condition
column and for the Report Name argument. When using temporary variables as a setting for an
argument, you must use an equal (=) sign in front of the expression:

=[TempVars]![ReportName]

There are still two OpenReport actions in this macro. Certain arguments — such as View —
don’t allow the use of temporary variables in expressions. Because one of your variables is a setting
for the report’s view, you still have to use the Condition column to decide which view to open the
report in.

The last two RemoveTempVar lines remove the temporary variables — ReportName and
ReportView — from memory. Because these variables probably won’t be used later on in the
application, it’s important to remove them.

Using temporary variables in macros gives you far more flexibility in Access 2007 and 2010 than in
previous versions. You can use these variables to store values to use later on in the macro, or any-
where in the application. Just remember that you only have 255 temporary variables to use, so don’t
forget to clean up after yourself by removing them from memory once you’re finished using them.

Using temporary variables in VBA
You may start out using macros to automate your application, but over time, you may begin using
VBA code to automate and add functionality to other areas. What do you do with the temporary
Free download pdf