set multiple form filters (1 Viewer)

cpampas

Registered User.
Local time
Today, 12:44
Joined
Jul 23, 2012
Messages
218
Hello
I am having a hard time setting multiple filters to my main form
the following went just fine :
Code:
 strfilter = "[distritoID]  = " & Me.searchDist & " And concelhoid = " & Me.searchConc & " And freguesiaid = " & Me.searchFreg
    Me.FilterOn = True
    Me.Filter = strfilter

Now i am trying to add a filter on the field datafim wich is a date/time field in the format 02/09/2021 08:02:49
Code:
strfilter = strfilter & " And dataFim > " & Now()
    Me.FilterOn = True
    Me.Filter = strfilter

it produces an error "syntax error , missing operator"

Any thoughts ?
 

CJ_London

Super Moderator
Staff member
Local time
Today, 19:44
Joined
Feb 19, 2013
Messages
16,553
try

strfilter = strfilter & " And dataFim > Now()"

but the error implies strfilter is not what you think it is - use debug.print to check

for the future, include all your code - for all we know you're second part is in a different sub and strfilter is a local variable

as an aside, how you see the date (i.e. the format) is irrelevant, formats are not used in date comparisons
 

cpampas

Registered User.
Local time
Today, 12:44
Joined
Jul 23, 2012
Messages
218
Cj_London
I see it now, strFilter is not supposed to return records, it's just a string
It worked just fine as you suggested.
Thanks
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 15:44
Joined
Feb 19, 2002
Messages
42,973
strfilter = strfilter & " And dataFim > Now()"
Now() includes time of day and using it when you mean Date() can result in inaccurate results.
 

cpampas

Registered User.
Local time
Today, 12:44
Joined
Jul 23, 2012
Messages
218
Now() includes time of day and using it when you mean Date() can result in inaccurate results.
Actually I was trying to set a filter where the field "dataFim" is greater than now() + 1 hour

strfilter = strfilter & " And dataFim > Now()+1"
this will set the limit to one more day, any ideas as to how to set it to one more hour ?
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 03:44
Joined
May 7, 2009
Messages
19,169
strfilter = strfilter & " And dataFim > DateAdd('h',1, Now())"
 

CJ_London

Super Moderator
Staff member
Local time
Today, 19:44
Joined
Feb 19, 2013
Messages
16,553
for future reference

dataFim > Now()+1"
this will set the limit to one more day, any ideas as to how to set it to one more hour ?


date time is a decimal number. To the left of the point is the number of days since 31/12/1899 and to the right is the time expressed as the number of seconds so far today divided by 86400 (number of seconds in a day)

An hour is 3600 seconds, so you should add 3600/86400 to advance an hour from now.

Or use Arnel's solution which is a standard way of doing it
 

Users who are viewing this thread

Top Bottom