![]() |
Tables & Queries: |
![]() Did you want: Working with Databases: Access 2007, 2010, 2013, 2016 | ||||
|
![]() |
You can create a query that asks for your input and uses that input as part of the criteria. The input is called a parameter, which just means something that can have different values which determine the behavior or value of something else. For example, temperature, pressure, humidity, and density are parameters the affect the weather. If you vary any of them, you change the weather. In the case of queries, changing a parameter will change the results of the query. How To Create a Parameter QueryAny query that uses criteria can easily be turned into a parameter query.
|
![]() |
Project 3: Tables & Queries
| |||||||||
Example: Parameter QueryThe query QCount of Test Grades by Class, groups the scores for an assignment or test based on the class and letter grade. A particular assignment/test ID has to be entered in the Criteria line. It is more flexible to have the query ask which assignment to look at.
By writing [Enter Assignment/Test ID#:] in the Criteria cell instead of entering a specific ID number, when the query runs, a dialog appears that repeats what was typed between the square brackets. When you fill in the value and click OK, the query runs, with the input as the criteria. A much more flexible query than before! In this case the user had to know the ID number of the assignment or test that she wants to look at. You can also create a form with a Lookup field that will show you what the choices are. When the choices are not completely obvious or the list is long or there are multiple parameters, a form can make it much easier to enter the right values. Keep the brain strain to a minimum!
When Access cannot find a value that the query asks for, it pops up a parameter dialog for you to fill in the value. The dialog shows the field that needs a value and its source, whether a table or query. The problem can be with an expression in the query or with a record. Access does not tell you which! The most common cause of this confusion is mis-spelling a field name in an expression in the Query Design View. It can also occur if the query is trying to match records between tables or queries and a record is blank in the field that joins the tables/queries. The example dialog shows that the FullName field does not have a value. The query was one that Access created in the background as part of a complex query to calculate grades. A record in the Scores table had an ID number but was blank otherwise. Access tried to match the blank score with a student, using the StudentID, in order to calculate the FullName. Naturally it failed to find a student with a blank StudentID. In this case, clicking OK without typing in anything ran the rest of the query just fine.
Start with:
Create a Parameter QueryIt is easy to turn a query into a parameter query. Just add a phrase/sentence inside square brackets to the criteria row.
| ||||||||||||
![]() |
~~ 1 Cor. 10:31 ...whatever you do, do it all for the glory of God. ~~ |