Microsoft KB Archive/208630

= ACC2000: How to Reference Parameters in Reports =

Article ID: 208630

Article Last Modified on 7/14/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



This article was previously published under Q208630



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

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).



SUMMARY
This article describes how you can reference the parameters of a report's RecordSource query or view. 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 file, RptSmp00.mdb. For information about how to obtain this sample file, please see the following article in the Microsoft Knowledge Base:

231851 ACC2000: Microsoft Access 2000 Sample Reports Available in Download Center



Steps for an Access Database
The following example demonstrates how to display the parameters from a report's RecordSource query in an Access database:

CAUTION: If you follow the steps in this example, you modify the sample database Northwind.mdb. You may want to back up the Northwind.mdb file and follow these steps on a copy of the database.

 Open the sample database Northwind.mdb 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. 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 window, click Reports under Objects, and then click New. In the New Report box, click AutoReport: Tabular, click the ProductReport query in the Choose the table or query where the object's data comes from box, and then click OK.</li> 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 ControlSource property of the text box to the following 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/97. When prompted for the End Date, enter 01/1/98. Note that when viewed in Print Preview, the report header now has the following text:

Report Period From 8/1/97 Through 1/1/98

</li></ol>

Steps for an Access Project
The following example demonstrates how to display the parameters from a report's RecordSource query in an Access project:

CAUTION: If you follow the steps in this example, you modify the sample Access project NorthwindCS.adp. You may want to back up the NorthwindCS.adp file and follow these steps on a copy of the project.

<ol> Open the sample Access project NorthwindCS.</li> Click Stored Procedures under Objects, and then click New.</li>  Type the following in the new procedure: Create Procedure ProductRepSp (@BeginDate datetime, @EndDate datetime) As

SELECT Orders.OrderID, Orders.OrderDate, Products.ProductName FROM Orders INNER JOIN [Order Details] ON    Orders.OrderID = [Order Details].OrderID INNER JOIN Products ON    [Order Details].ProductID = Products.ProductID WHERE (Orders.OrderDate BETWEEN @BeginDate AND    @EndDate) </li> Save the stored procedure as ProductReportSP, and then close it.</li> In the Database window, click Reports under Objects, and then click New.</li> Click Design View and click OK. Do not choose a source from the Choose the table or view where the object's data comes from box.</li> Click Properties on the View menu.</li> On the Data tab, in the Record Source field, type ProductReportSP .</li> Close the Properties dialog box.</li> From the field list box, drag OrderID, OrderDate, and ProductName to the details section of the report.

NOTE: To take out unnecessary blank space from the detail section, you may need to move the page footer bar up closer to the fields that you added.</li> Add a text box to the header section of the report.</li>  Set the ControlSource property of the text box to the following expression: <pre class="fixed_text">="Report Period From" & " " & [@BeginDate] & " " & "Through" & " " & [@EndDate] </li> <li>On the View menu, click Print Preview. When prompted for the Start Date, enter 08/08/97. When prompted for the End Date, enter 01/1/98. Note that when viewed in Print Preview, the report header now has the following text:

Report Period From 8/1/97 Through 1/1/98

</li></ol>

<div class="references_section">