Print the Value of a Parameter on a Report

Problem

You’ve created a report based on a parameter query that prompts the user for one or more parameters when the query is run. The report works just fine, but you’d like to be able to document somewhere on the report what parameter values were entered by the user. That way you’ll know, for example, which years’ records are included in the report. Is there any way to do this with Access?

Solution

Although this capability is not well documented, you can print the values of query parameters on a report by referring to the parameters as if they were fields in the underlying query. This solution shows you how to create controls on a report that document the user-entered runtime parameters.

Load the 03-02.MDB database and open the qryAlbumsPrm query in design mode to verify that this query has three parameters (Figure 3-3). Now open the rptAlbumsPrm in preview view. Because this report is based on qryAlbumsPrm, you will be prompted for the three parameters.

The qryAlbumsPrm parameter query includes three parameters

Figure 3-3. The qryAlbumsPrm parameter query includes three parameters

Enter your values at the parameter prompt. If you enter the parameter values from Table 3-1, you should see a report that looks similar to the one shown in Figure 3-4.

Table 3-1. Parameters and sample values for qryAlbumsPrm

Parameter

Sample value

Type of music?

Rock

Starting year?

1960

Ending year?

1979

Figure 3-4. The ...

Get Access Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.