"How do I include a the paramaters of a query in a report?" This is one of the most commonly asked questions that beginner and intermediate Access users will post in the newsgroups. Let me explain the question. Most reports in Access are based on an underlying query. Some of those queries are "paramaterized" (yes, that's a real word) which means that the query prompts the user for some data THAT'S USED BY THE QUERY. The most common use for a parameter (PROMPT) is in the WHERE clause or (for you beginners) in the Criteria cell of the query. Let's say that you have a query and one of the fields in the query is STATE. You could put a Parameter (PROMPT) into the query, say "Please enter a 2-letter state code?", and when executed it would only show records that had a state value that matched what you typed in. A Parameter is used in a query by simply placing square brackets ( [ ] ) around your prompt question. For the "state" example mentioned above, in the criteria cell of the QBE grid in the STATE field you would type the following:
[Please enter a 2-letter state code?]
When the query is executed, the user would be prompted as above to enter the state code. WHATEVER THEY TYPE WILL BECOME THE CRITERIA FOR THE STATE FIELD. This method can also be used to enter a Date Range by typing something like the following into the criteria cell of a Date field (Birthday for example):
Between [Enter a Start Date] and [Enter an End Date]
In this example the user would be prompted twice (once for each parameter) and the query would return records where the date was between the first prompt and the second prompt (or to be more technically accurate, all dates that were greater than the first prompt and less than the second prompt).
Now back to our question: "How do I include the paramaters of a query in a report?" The question at hand is this. How can I display the parameters (that I typed in) when the report's underlying query runs. In other words, you run a report. The report executes the query that the report is based on. The query prompts you for each of its parameters. The report is displayed (or printed). The question is "how can I make the report print (or display) whatever I typed at the parameter prompt?"
Now for our trick. Many of you intermediate users probably already knew how to include a parameter (PROMPT) in a query. (In fact the discussion above was included mostly for the sake of the newbies.) But many intermediate users are NOT aware of the following, a tip that makes including a user's answer to a prompt very simple. KEY CONCEPT: You can include a parameter TWICE in the same query, once as a field's Criteria (as demonstrated above) and AGAIN AS A SEPARATE FIELD IN THE SAME QUERY. Let me illustrate using the above date range example. If you recall, you can enter the following into the criteria cell of a date field:
Between [Enter a Start Date] and [Enter an End Date]
You can also enter the following values into two separate Field cells of the QBE grid:
BeginDateRange: [Enter a Start Date]
EndDateRange: [Enter an End Date]
Notice that the Parameters in the Field cells exactly match the parameters in the Criteria cell. KEY CONCEPT: Because they match, the query will only prompt you twice (in this exampe, once for each unique parameter) not four times. And whatever you type will become new fields (columns) in the query's returned result set: BeginDateRange and EndDateRange. To show them in your report simply drop them in the report as you would any other field. If you include them in the report header, they will only show once.