Microsoft KB Archive/141613

= ACC: How to Reference Parameters in Reports =

Article ID: 141613

Article Last Modified on 1/19/2007

-

APPLIES TO


 * Microsoft Access 2.0 Standard Edition
 * Microsoft Access 95 Standard Edition
 * Microsoft Access 97 Standard Edition

-



This article was previously published under Q141613



Moderate: Requires basic macro, coding, and interoperability skills.



SUMMARY
This article describes how you can reference the parameters of a report's RecordSource query. You can use this method to display the parameters in a text box in the report.

NOTE: This article explains a technique demonstrated in the sample files, RptSampl.exe (for Microsoft Access for Windows 95 version 7.0) and RptSmp97.exe (for Microsoft Access 97). For information about how to obtain these sample files, please see the following articles in the Microsoft Knowledge Base:

145777 ACC95: Microsoft Access Sample Reports Available in Download Center

175072 ACC97: Microsoft Access 97 Sample Reports Available in Download Center



MORE INFORMATION
The following example demonstrates how to display the parameters from a report's RecordSource query:

 Open the sample database Northwind.mdb (or NWIND.mdb for in Microsoft Access 2.0) and create a new query based on the Orders, Order Details, and Products tables. Include the OrderID and the OrderDate fields from the Orders table and the ProductName field from the Products table.

NOTE: In Microsoft Access 2.0, there is a space in the Order ID, Order Date, and Product Name fields. On the Query menu, click Parameters. In the Query Parameters box, under Parameters, type Enter Start Date, and under Data Type enter Date/time. Press TAB to move to the next Parameter field. Under Parameters, type Enter End Date and under Data Type, enter Date/time. Click OK. Add the following criteria for the OrderDate field:

Between [Enter Start Date] And [Enter End Date] Save the query as ProductReport, and then close it. In the Database windows, click the Reports tab, and then click New. Select the ProductReport query, then select AutoReport: Columnar. (In Microsoft Access 2.0 select the ProductReport query, click the Report Wizard Button, and then Select AutoReport.) When the AutoReport Wizard prompts for a Start and End date, click OK each time, and when the wizard presents the new report in Print Preview, click Report Design on the View menu.</li> Add a text box to the report's header section.</li>  Set the text box's ControlSource property to the following expression.

NOTE: In the following expression, an underscore (_) at the end of a line is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this expression.

<pre class="fixed_text">     ="Report Period From" & " " & [Enter Start Date] & " " & "Through" _ & " " & [Enter End Date] </li> On the View menu, click Print Preview. When prompted for the Start Date, enter 08/08/94. When prompted for the End Date, enter 01/1/95. Note that when viewed in Print Preview, the report header now has the text, "Report Period From 8/1/94 Through 1/1/95."</li></ol>

<div class="references_section">