Trying to filter date with textbox input

5hadow

Member
Local time
Yesterday, 19:45
Joined
Apr 26, 2021
Messages
89
Can someone explain why this doesn't work?

Code:
Private Sub btnFilterDate_Click()
    Dim DueDate As Date
    DueDate = DateAdd("d", Me.tbxFilter.Value, Now())
    Me.Filter = "ReviewDue <= duedate"
    Me.FilterOn = True
End Sub

I want to filter ReviewDue by today + what ever number is in tbxfilter.
 
Try:
Code:
Me.Filter = "ReviewDue<=" & DueDate
 
Try

Me.Filter = "ReviewDue <= #" & duedate & "#"
 
in case your Regional date setting is not EN(US):

Me.Filter = "ReviewDue <= #" & Format$(duedate, "mm\/dd\/yyyy") & "#"
 
As long as the control is bound to a date data type field or if the field is unbound, then the format must specify a date format, then this will work:

Me.Filter = "ReviewDue<=" & Me.DueDate

It doesn't need octothorps because it isn't formatted.

A brief test would suggest otherwise. The textbox is bound to a field with the date/time data type and the format of the textbox is short date (also doesn't work if the textbox is unformatted). The first line does not error but does not return any records. The second line returns the expected records.

'DoCmd.OpenReport "rptReservations", acViewPreview, , "StartDate = " & Me.StartDate
DoCmd.OpenReport "rptReservations", acViewPreview, , "StartDate = #" & Me.StartDate & "#"
 
Glad it worked for you.
 

Users who are viewing this thread

Back
Top Bottom