Query dates

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,338
Office Version
  1. 365
Platform
  1. Windows
I have a date field (PDIR Completed). I would like to have a form that shows a query. But I want that query to based off a selection from a pulldown on my form (example of list: Last 7 Days, Last 14 Days, Last 30 Day and Last 60 Days)

If I select "Last 7 Days" I want the query (and therefore the Form) to only show the records where the PDIR Completed date was in the last seven days from today.

Any suggestions?
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You will want to use the DateDiff function to figure out your date to query against DateDiff ( interval, date1, date2, [firstdayofweek], [firstweekofyear]).

You will need to use VBA code to determine your date, then apply a filter. You can also save the target date on a hidden field on your form, then use that hidden field as a criteria in your query. In this approach, you will need the Me.Requery statement to refresh the query.

I hope that gets you started. Post back if you need more help...
 
Upvote 0
I would have said you would just need ">= date() - NumberOfDays"

How you decide the number is up to you.?
The combo could have
Code:
Field1   Field2
7          Last 7 Days
14        Last 14 Days
30        Last 30 days
60        Last 60 days
then just use the first element of the row selected

">= date() - " & Me.cboDays & " ORDER BY YourDate"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,431
Members
448,961
Latest member
nzskater

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