Introducing a date filter to my search form (1 Viewer)

ECEK

Registered User.
Local time
Today, 02:12
Joined
Dec 19, 2012
Messages
717
I have the following code in my form.
It is a cumulative search but I'm really struggling to filter by a specific date.
My date field is [SelectedPeriod]
When the form opens the fields t6 and t7 are defaulted to two dates that will ensure that all of the the data is filtered ie. t6 -01/01/2000 and t7 = 01/01/2020
I use AfterUpdate to call this code.
I want to be able to incorporate t6 and t7 into my existing filter.
I just can't seem to get it to work.
Any pointers ?

Code:
Private Sub subChangeFilter()

If Nz(Me.t1, "") <> "" Then
strfilter = strfilter & "ID like '*" & Replace(Me.t1, "'", "''") & "*' and "
End If

If Nz(Me.t2, "") <> "" Then
strfilter = strfilter & "Client like '*" & Replace(Me.t2, "'", "''") & "*' and "
End If

If Nz(Me.t3, "") <> "" Then
strfilter = strfilter & "Campaign like '*" & Replace(Me.t3, "'", "''") & "*' and "
End If

If Nz(Me.t4, "") <> "" Then
strfilter = strfilter & "Last_Name like '*" & Replace(Me.t4, "'", "''") & "*' and "
End If

If Nz(Me.t5, "") <> "" Then
strfilter = strfilter & "First_Name like '*" & Replace(Me.t5, "'", "''") & "*' and "
End If

If Nz(Me.t6, "") <> "" Then
'THIS IS WHERE I WANT TO FILTER BY DATE T6 BEING THE START DATE ie. SelectedPeriod >= T6
End If

If Nz(Me.t7, "") <> "" Then
'THIS IS WHERE I WANT TO FILTER BY DATE T7 BEING THE END DATE ie  SelectedPeriod<=T7
End If

If strfilter <> "" Then
strfilter = Left(strfilter, Len(strfilter) - 4)
End If

Debug.Print strfilter

Me.Filter = strfilter
Me.FilterOn = True

End Sub

Or (seeing as how there are defaulted dates in both t6 and t7) have a between filter in both of the AfterUpdate of t6 and t7

Thanks for your time in advance.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:12
Joined
May 7, 2009
Messages
19,231
If Nz(Me.t6, "") <> "" Then
strFilter = strFilter & "[SelectedPeriod] >=#" & Format(Me.T6, "mm/dd/yyyy") & "# And "
End If

If Nz(Me.t7, "") <> "" Then
strFilter = strFilter & "[SelectedPeriod] <=#" & Format(Me.T7, "mm/dd/yyyy") & "# And "
End If
 

Minty

AWF VIP
Local time
Today, 02:12
Joined
Jul 26, 2013
Messages
10,366
I think you'll need the dates to be formatted with octothorpes #01/01/2018# and possibly in a yyyy/mm/dd styleee for it to all work.
 

ECEK

Registered User.
Local time
Today, 02:12
Joined
Dec 19, 2012
Messages
717
Arnel
Thank you so much. works a treat!
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 09:12
Joined
May 7, 2009
Messages
19,231
ur welcome.
 

Users who are viewing this thread

Top Bottom