Date Filter Query

VaYooper

New Member
Joined
Mar 12, 2015
Messages
31
Hello,

Was wondering if someone could help with a date filter query I'm trying to add to a subform.

The selections I want are 'Within the past year' , 'Greater than a year' , and 'Never' What each of these selections would do is give me records that have a login date within the past year of today's date, greater than a year from today's date, and no record of today's date. Thank you for whatever assistance you can provide.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Sorry... meant to say

login date within the past year of today's date, greater than a year from today's date, and no record of any date.
 
Upvote 0
To calculate the data a year from the current date use this function:

Code:
DateAdd ( interval, number, date )


To get the date one year ago from the current data use:

Code:
DateAdd("yyyy",-1,Date())


Example where Date() = 03/15/2015:

Code:
? DateAdd("yyyy",-1,Date())
3/15/2014



'Within the past year'

Code:
>= DateAdd("yyyy",-1,Date())


'Greater than a year'

Code:
< DateAdd("yyyy",-1,Date())


'Never'

Don't know what you mean by this. Please explain in more detail
 
Upvote 0
Sorry... by 'Never' I mean that they do not have a last login date so the date is blank or null.
 
Upvote 0
For the functions that you have provided. Where would I put these? Somewhere in the combo box properties?
 
Upvote 0
For the functions that you have provided. Where would I put these? Somewhere in the combo box properties?

I am only guessing that combo box you are referring to has the selection list of 'Within the past year' , 'Greater than a year' , and 'Never' .

The criteria examples I gave you would be for a date filter criteria for the query you are adding to your sub form.

the way I would handle this is to use the After Update Event of the Combo box to build the SQL for the record source of the sub form.
 
Upvote 0
I think I see where the confusion is. Let me start over.... In a table I have columns Last Name, First Name, Department, Access_Type, Login Date. This table has all personnel that have access to a particular program we have and it shows the last time that they logged into this particular program. So the dates in the login date column of my table can be from yesterday, 1 year ago, 4 years ago etc... but the login date can also be blank because they never logged into the program. So in this form I want the combobox to have three options: 'Within the past year' , 'Greater than a year' , and 'Never'. So when I click on 'Within the past year' this filters the data to only include records with a login date < 1 year or login date > 1 year by choosing 'Greater than a year' or login date is blank if they choose 'Never'. Hopefully I explained my situation better this time, thank you.
 
Upvote 0
Use the after update event of the combo box to apply the desired

I will assume the field is named LogonDate. You may need to change it to you actual field name


'Within the past year'

Code:
[LogonDate] >= DateAdd("yyyy",-1,Date())

'Greater than a year'



Code:
[LogonDate] < DateAdd("yyyy",-1,Date())



'Never'

Code:
IsNull([LogonDate])
 
Upvote 0

Forum statistics

Threads
1,221,893
Messages
6,162,659
Members
451,780
Latest member
Blake86

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