variable criteria in a query

j3andc

Board Regular
Joined
Mar 4, 2002
Messages
172
I am new to Access, so forgive me if this is a simple question. When I run a query (or a report) I want to apply specific criteria for each time I run the query. I can not figure out what to put in the criteria field in the design view of the query so I can get specific results each time I run the query.

Jim
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi,

What is the criteria you need to change?

The simpilest way is to put something like:

[Enter Name] in the name field, this will open a promt each time is is run.
However a better way in to control it from a Form.

Regards,
 
Upvote 0
That is a great start. If the table contains numbers or dates how do I use "<" or ">" to find a range of values?
 
Upvote 0
You can use >=[Enter Start Date] and <=[Enter End Date]

I would consider using a Form for this.

Your Starter for 10:

Create a simple
Add 2 Textboxes, rename them txt_StartDate and txtEndDate

Save the form, say frm_TestDates

Open your Query.

Right-click on the criteria and choose Build...
Select Forms>All Forms>frm_TestDates

in the top box type >=
You should then be able to select the txt_StartDate from the bottom middle box.

Your syntax should look like this:

>=[Forms]![frm_TestDates]![txt_StartDate]

Do the same for EndDate.

<=[Forms]![frm_TestDates]![txt_EndDate]

Save the Query.

Goto the design view of your Form

Add a button,
In the new dialogue box select Miscellaneous>Run Query
Choose your query
Run through the rest of the wizard as you wish.

now you can load the form and enter a Start Date and End Date.
Hit the button, and Bingo.

Hope that gets you started

Regards,
 
Upvote 0
Do I need to put something between >=[Forms]![frm_TestDates]![txt_StartDate] and <=[Forms]![frm_TestDates]![txt_EndDate]
 
Upvote 0
j3andc said:
Do I need to put something between >=[Forms]![frm_TestDates]![txt_StartDate] and <=[Forms]![frm_TestDates]![txt_EndDate]

Hi,

that should be the Exact systax you need:

>=[Forms]![frm_TestDates]![txt_StartDate] And <=[Forms]![frm_TestDates]![txt_EndDate]

This goes in your Date field.
Once you leave the criteria box the and should change to And, capitalised.
This return the records within the dates you enter in the text boxes.

Regards,
 
Upvote 0
You could use Between

eg

Between [Forms]![frm_TestDates]![txt_StartDate] And [Forms]![frm_TestDates]![txt_EndDate]
 
Upvote 0
You could also do it in SQL view by using :

between Forms.frm_TestDates.txt_StartDate & " " and Forms.frm_TestDates.txt_EndDate & " "
 
Upvote 0
I got it to work. Is there a way to write the formula so I can leave one or both of the fields blank and it would still work.
 
Upvote 0

Forum statistics

Threads
1,221,799
Messages
6,162,030
Members
451,738
Latest member
gaseremad

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top