| |
|
| |
| |
|
Microsoft Access Parameter Query
Asking the user for criteria when you run your queries
Q: I would like my users to be able to change the
criteria for a query, but not have to learn how to make design changes.
For example, when I run a query of customers by state, I want the user
just to be able to type in the state when the query runs - perhaps with
a prompt. Any ideas?
A: To do this, use an
Parameter Query. To do this, just place a criteria for the field(s)
you want to have parameters for, and put a prompt for your user inside
of square brackets. Like this:

Now when your query runs, you'll be prompted to enter the state as a
parameter.

Here is a FREE VIDEO TUTORIAL
that will walk you through this topic in detail.
I teach the concepts in this free mini tutorial in my
Access 102 course. These are
full courses - over 60 minutes in length each. I spend a lot more time going
over how to do this, in addition to lots more tips and tricks.
| | |
Student Interaction:
Creating a Parameter Query
|
Richard on 4/1/2008:
I hope you enjoyed this free tutorial. Please post any questions or comments you have here. |
Gregg on 9/29/2009: How do you get an Access 2007 parameter query to prompt the user "Record Not Found" when an input value is not on the dataset?
|
Richard Rost on 9/29/2009: Gregg, you can't do this with just a parameter query. You would need something a little more advanced, like a DCOUNT statement in some VBA code to count the number of records returned.
|
Mark on 12/20/2009: How can i Query the Hours Worked Table and cal the Total Number of Hours and Total Payment made by customer.
|
Richard Rost on 12/21/2009: Mark, to get the total number of hours you would use a second query - make it an Aggregate Query and use the SUM function. The same would go for totaling payments.
|
Bobbin on 9/7/2010: Consider there is a Table with Admit date and and discharge date fields both are same format as follows(10/01/2008). How it is possible If I need to select the customers for last 3 months with admit date/discharge date, How its possible to create query for summary with month if the dates are given in above format
|
Ken on 9/1/2011: The only thing wrong with the parameter query,is that you can't use it when you are using a lookup list on your fields.
|
John Mason on 3/6/2012: I am using a parameter query to open a form, using the SSN field, and that works wonderfull, however if the SSN is not in table, it opens a blank form, which is fine, but I would like it to populate the SSN field (1st tab) when it opens the blank. Is there a way to do this?
Reply from Richard Rost:
Of course there's a way to do it. There's a way to do just about everything in Access. Unfortunately, I can't think of a way to do this that DOESN'T involve a little programming. Once you type that parameter into Access' default prompt, there's not a lot else you can do with it.
You could set up your own form that's not bound to a table. All you need in that form is a single text box and a command button. Type the SSN into the text box and click the button to search. The button would execute a DLOOKUP command to see if the value exists in your table. If it does, you would open the person form to that record. If not, you would open the form to a blank record and set the value.
Like I said, this will involve a little bit of programming. I cover all of this in my 300-level Access classes. Unfortunately, I can't think of a NON-programming solution for this problem. Anyone else?
|
|
|
| |
|
You may want to read these articles from the 599CD News: |
|
|
|