Conditional Query Criteria

paulkc

Board Regular
Joined
May 18, 2007
Messages
220
Office Version
  1. 365
I would like to be able to run a query based on the date in a particular field. I want to run certain days of the week such as Thursday - Wednesday beginning with the current week. I cannot seem to figure out how to get this work.

I have also tried to use a parameter but for some reason the query does not return any records when I put the date in through a parameter input. If I put that same date in as criteria, it works fine. Any thoughts on that?

What I would really like to do is be able to enter a desired start date and run 7 days beginning with that date.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
As long as your date is in Date format (and not Text), you can create a paramter query by enterting criteria like this:

Between [enter start date] And [enter end date]

This will prompt you to enter a start date and end date and return all records that fall in between the two. Just enter the dates like a normal date (do not need to surround with #'s).
 
Upvote 0
I've tried that. Just to clarify the original date fields is in a Text format. I then use CDate function to convert it to date format so I can query it. I don't know if that is why I am having trouble or not but I thought I would mention it.

Assuming that this should work and I am just making a simple error, can I use it twice in an expression such as this: Between [Enter Start Date] And [Enter Start Date] +7
Will this work so I only have to enter it once and it automatically calculates the end date based on the start date?
 
Upvote 0
I've tried that. Just to clarify the original date fields is in a Text format. I then use CDate function to convert it to date format so I can query it. I don't know if that is why I am having trouble or not but I thought I would mention it.
Are you using the CDATE function in the same query as where you are entering your expression? Sometimes Access is a little picky on running criteria on calculated fields, especially if you are converting data types. Try converting to a date using the CDATE function in one query, then create a new query based on this query where you apply the criteria and see if that works (sometimes it helps to have the intermediate "helper" query).

Assuming that this should work and I am just making a simple error, can I use it twice in an expression such as this: Between [Enter Start Date] And [Enter Start Date] +7
Will this work so I only have to enter it once and it automatically calculates the end date based on the start date?
No, it doesn't like that. Try it and you will see that you get an error. If you want to go this way, I would recommend creating a user selection Form where they enter the criteria, and build off of that.
 
Upvote 0
That is getting a little more involved than I would like to be at this point. What approach could I use to just start on Wednesday of the current week and end on the following Tuesday?
 
Upvote 0
That is getting a little more involved than I would like to be at this point. What approach could I use to just start on Wednesday of the current week and end on the following Tuesday?
I think it may be possible to write a formula to do that, but that may end up being more complex than creating a selection Form.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,710
Members
452,939
Latest member
WCrawford

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