PDA

View Full Version : Create user input query



john3j
10-04-2009, 10:22 AM
I have a database that has make table queries. I also have several divisions, division is also a column in each query. Instead of creating queries particular to each division, is there a way to get access to prompt the user to select which division they want to see a report for, or a drop down list for them to select which division they want to run the query for? Any help would be great!

orange
10-04-2009, 10:49 AM
I have a database that has make table queries. I also have several divisions, division is also a column in each query. Instead of creating queries particular to each division, is there a way to get access to prompt the user to select which division they want to see a report for, or a drop down list for them to select which division they want to run the query for? Any help would be great!
Here's a link with info that may be helpful to you

http://www.fontstuff.com/access/index.htm (http://www.fontstuff.com/)

Good luck

OBP
10-05-2009, 02:45 AM
Create a form with an an Unbound Combo box based on the Divisions (the divisions should be in a separate table for use with a combo to slect them for the Main Table as well).
In the Query enter the following in the Division Column's first Criteria Row

forms![Formname]![Comboname]

where Formname is the actual name of your form and Combname is the actual name of your combo.
Note that this methoc uses the First Column of the Combo so it must match the division in the query in the type of field i.e. text must equal text or number must equal number.

There are numerous examples on this forum showing this technique.

CreganTur
10-05-2009, 07:44 AM
I completely agree with Tony- linking your query to a Form object is the simplest way to utilize your user's criteria.

What you're setting up is a parameter query- it's a type of query that asks the user to provide criteria for the query to use. In its simplest form, the query will show InputBoxes to the user, asking for specific criteria. The problem with this type of parameter query is that the user can enter anything, literally, into the inputbox, even values that don't conform to the data type the query needs or things that just don't make sense.

Doing this through Tony's directions allows you to control the data through a Form, which means you can place validation checks on what gets passed to the query. This is great because you can restrict the user so they can only provide a date when a date is needed, or use a combobox so they can only choose from a restricted list of valid options.

HTH:thumb