Now that we have learned to create a simple query on a single table using the query Wizard and also learned to get an output for a given criteria. But then we had to enter the required parameter/query at the time of the creation of the query in the “Design Mode“.
But what if you want to enter/pass the criteria on the fly or say dynamically? It would be very cumbersome to enter the criteria every time. It could also pose a risk to enter the same in the design Mode as the query could get changed in case the user is not conversant with MS Access.
This problem could be overcome by using the feature given by MS Access so as to enable the user the enter the criteria/parameter on the fly or at the time the query is executed to run (before the output is displayed).
Let’s understand how do we use the same and we will use the same pin code data table to understand the same.
Let’s say we are creating a query having the columns “officename“, “Pincode“, “regionname” based on the table “Pincode_data”
The steps to be followed for creating the query is as same in the previous blog (till you open the query in the “Design Mode“), hence i will not repeat the same here and you need to refer to the same using the link below…
Blog#14 : Creating a simple query for a given or required Criteria/Value
The Query is to named and saved as “Query2 with Criteria”
Once the query is in the design mode, you need to enter the text [Enter Region Name] in the row named “Criteria” below the column name “regionname“.
The text [Enter Region Name] pops as a dialogue box prompting the user to enter a Value which is then passed on the query that is being executed which it uses to give the desired output.
Image of the query in Design Mode.
Image of the Input Dialogue Box that appears when the query is Run/Executed.
You can enter the relevant Value that is to be passed on to the Query for execution. Examples of Values like “Mumbai“, “Delhi” etc etc ….
Based on the Input Value the Query will be return the output data… in case there is no data in the table based on the value passed using the above dialogue box, the query will not return any data.
Pasted below is the link of the Video demonstrating the same.
Useful Tip – Instead of creating a new query using the query Wizard, a new query can be created using Copy and Paste option, try creating “Query2 with Criteria” using this method, Copy the query named “Query1 with Criteria” using the Ctrl+ C option and pasted using the Ctrl + V option with query name as “Query2 with Criteria“. The remaining process remains the same.