Solved Filter by date a variable number of days into the future. (1 Viewer)

lwvogan

New member
Local time
Today, 09:27
Joined
Aug 19, 2017
Messages
10
I am trying to filter a form that displays data from an employees table. Each employee record has a scheduled departure date: [EndDate]. I want a user to be able enter the number of days into the future that they want to see upcoming departures: textBoxDays. For example, if the user wants to see a list of employees that will depart in the next month, they would enter 30. If they want to see the departure list for the next six months, they enter 180. In a query that works for a set period, the criteria for the field EndDate is < Date()+30. I want to be able to have EndDate < Date() + textBoxDays.

I have tried many combinations in the after update event but none seem to work. Thanks in advance.
 

June7

AWF VIP
Local time
Yesterday, 16:27
Joined
Mar 9, 2014
Messages
5,490
I would build filter criteria in VBA:

Me.Filter = "EndDate BETWEEN Date() AND Date() + " & Me.textBoxDays
Me.FilterOn = True

If you must have parameterized query object, then need full reference to form and control, something like:

SELECT Employees.* FROM Employees WHERE EndDate BETWEEN Date() AND Date() + Forms!formname.textBoxDays
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 08:27
Joined
May 7, 2009
Messages
19,246
you already have the correct criteria for the query:
Between Date() And DateAdd("d",Date(),[Forms]![FormEmployees]![txtDays])
 

Attachments

  • Departure.accdb
    576 KB · Views: 66

lwvogan

New member
Local time
Today, 09:27
Joined
Aug 19, 2017
Messages
10
I tried “Me.Filter = "EndDate BETWEEN Date() AND Date() + " & Me.textBoxDays
Me.FilterOn = True” in the After Update event for the text box (textBoxDays) and it worked perfectly. I will check out the other options when I get on my computer. Thank you both.
 

Users who are viewing this thread

Top Bottom