Ms Access 简明教程
MS Access - Parameter Queries
关于查询的最佳部分是您可以保存并一次又一次地运行同一查询,但是当您仅通过更改条件反复运行同一查询时,您可能考虑使查询接受参数。
The best part about queries is that you can save and run the same query again and again, but when you run the same query again and again by only changing the criteria then you might consider the query to accept parameters.
-
If you frequently want to run variations of a particular query, consider using a parameter query
-
Parameter query retrieves information in an interactive manner prompting the end user to supply criteria before the query is run.
-
You can also specify what type of data a parameter should accept.
-
You can set the data type for any parameter, but it is especially important to set the data type for numeric, currency, or date/time data.
-
When you specify the data type that a parameter should accept, users see a more helpful error message if they enter the wrong type of data, such as entering text when currency is expected.
-
If a parameter is set to accept text data, any input is interpreted as text, and no error message is displayed.
Example
现在,我们通过创建参数查询来了解一个简单的示例。让我们打开数据库,然后在“创建表”选项卡中选择“查询设计”。
Let us now take a look at a simple example by creating a parameter query. Let us open your database and select Query Design in the Create table tab.
双击 tblProjects 然后关闭 Show 对话框。
Double-click on the tblProjects and close the Show dialog box.
选择您希望作为查询结果显示的字段,如下面的屏幕截图所示。
Select the field you want to see as a query result as shown in the following screenshot.
在查询设计网格中,在 ProjectStart 列的“条件”行中键入 [Enter a project start data] 。字符串 [Enter a project start data] 是您的参数提示。方括号表示您希望查询要求输入,而文本 Enter a project start data 是显示的参数提示。
In the query design grid, in the Criteria row of the ProjectStart column, type [Enter a project start data]. The string [Enter a project start data] is your parameter prompt. The square brackets indicate that you want the query to ask for input, and the text is Enter a project start data is the parameter prompt displays.
现在,我们运行您的查询,您将看到以下提示。
Let us now run your query and you will see the following prompt.
现在,让我们输入以下日期。
Let us now enter the following date.
单击“确定”以确认。
Click OK to confirm.
结果,您将看到该项目在 2/1/2007 开始的详细信息。让我们转到设计视图并再次运行查询。
As a result, you will see the details of the project which started on 2/1/2007. Let us go to the Design View and run the query again.
按上面屏幕截图所示输入日期,然后单击“确定”。现在,您将看到该项目在 5/1/2008 开始的详细信息。
Enter the date as in the above screenshot and click Ok. You will now see the details of the project which started on 5/1/2008.