25

Creating Parameter Queries

Parameter queries are used in Access when the values for criteria in the query are required to be passed to the query at run time instead of when the query was created. There are other ways to supply runtime arguments to queries, such as building the SQL string with the criteria or modifying the query's QueryDef, but these methods require the developer to know how to use VBA.

Access 2010 provides two simple ways for the developer to request that a user enter values, such as a date or an invoice number, before executing the query. In this lesson you learn how to use a simple popup Parameter Request dialog and use controls on a form with a command button to pass arguments to a query. You also learn how to explicitly define the data type of the parameter using the Query Parameters dialog.

LESSON SETUP

For this lesson you need Access 2010 and Lesson 25 files from the book's website at www.wrox.com. You should be familiar with creating database objects and working with queries to successfully complete this lesson.

PARAMETER QUERIES IN ACCESS

A Parameter query in Access is any query designed to accept user input to supply the values to be used as criteria in the query at run time. The easiest method to prompt a user to supply a value in a Parameter query is to use square brackets to surround a prompt for the user, such as [Enter the Customer Number] in the Criteria row of the CustomerNumber field. Each time the query is executed, a Parameter Request dialog ...

Get Microsoft® Access® 2010 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.