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.
- 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.
- Add a text box to the report's header section.
- Set the ControlSource property of the text box to the following expression:
="Report Period From" & " " & [Enter Start Date] & " " & "Through" & " " & [Enter End Date]
- 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
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.
-
Open the sample Access project NorthwindCS.
-
Click Stored Procedures under Objects, and then click New.
-
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)
- Save the stored procedure as ProductReportSP, and then close it.
- In the Database window, click Reports under Objects, and then click New.
- 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.
- Click Properties on the View menu.
- On the Data tab, in the Record Source field, type ProductReportSP.
- Close the Properties dialog box.
- 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.
- Add a text box to the header section of the report.
- Set the ControlSource property of the text box to the following expression:
="Report Period From" & " " & [@BeginDate] & " " & "Through" & " " & [@EndDate]
- 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