|[ Team LiB ]|
Recipe 3.2 Print the Value of a Parameter on a Report
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?
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.
Notice that the selected parameters are included in the page header of the report. Run the report again, entering different parameters, and verify that the new parameters are correctly printed on the report.
Follow these steps to print the values of query parameters on your own report:
During report design, you are free to reference any "unknown" you'd like as long as you put brackets around it. (If you don't put brackets around it and it's not a field in the underlying record source, Access thinks you entered a string constant and forgot to surround it with quotes, so it puts the quotes in for you.) When you run the report, Access tries to locate the unknown references. If it locates a query parameter or form control that satisfies the reference, it copies the value into the control and continues running the report. If it can't locate the unknown reference, however, it puts up a parameter dialog, requesting help in locating that unknown piece of data.
You can also create parameters directly on reports that are independent of query parameters. For example, you might use this type of "report parameter" if you create a report that requires a person's name and signature at the bottom of a page when you know that the name will vary every time you run the report (and cannot be obtained from the report's record source). Simply add a text box that references the new parameter—for example, [Enter signature name:]. Access will prompt you for this report parameter when you run the report, just as if you had defined the parameter in the report's underlying query.
|[ Team LiB ]|