If you expect to run a summary or another type of query repeatedly with changes to the criteria, you can convert the query to a parameter query. Parameter queries which Chapter 9 explained briefly enable you to enter criteria with the Enter Parameter Value dialog. Access prompts you for each parameter. For the qryMonthlyOrders1997 query that you created in the preceding section, the only parameter likely to change is the range of dates for which you want to generate the product sales data. The two sections that follow show you how to add a parameter to a query and specify the data type of the parameter. Adding a Parameter to the Monthly Sales QueryTo convert the qryMonthlyOrders1997 summary query to a parameter query, you first create prompts for the Enter Parameter Value dialog that appears when the query runs. You create parameter queries by substituting the text with which to prompt the user, enclosed within square brackets, for actual values. Follow these steps:
Specifying the Parameter's Data TypeThe default field data type for parameters of Access queries is Text. If the parameter creates a criterion for a query column of the Date/Time or Number field data type, you must assign a data type to each entry that is made through an Enter Parameter Value dialog. Data types for values entered as parameters are established in the Query Parameters dialog. If you have more than one parameter, you can establish the same or a different data type for each parameter. Note The data type for the prompt of the qryMonthlyOrdersParam query's parameter is Text (the default), not Date/Time. Thus you don't need to apply a data type specification for the query. Follow these steps to demonstrate adding an optional data type specification to a parameter:
Tip Complete your query design and testing before you convert any type of query to a parameter query. Using fixed criteria with the query maintains consistency during the testing process. Furthermore, you can make repeated changes between Design and Run view more quickly if you don't have to enter one or more parameters in the process. After you finish testing the query, edit the criteria to add the prompt for the Enter Parameter Value dialog. The parameter-conversion process described in this section applies to all types of queries that you create if one or more of the query columns includes a criterion expression. The advantage of the parameter query is that you or a user of the database can run a query for any range of values in this case, dates such as the current month to date, a particular fiscal quarter, or an entire fiscal year. |