set multiple form filters

cpampas

Registered User.
Local time
Today, 09:55
Joined
Jul 23, 2012
Messages
221
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 ?
 
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
 
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
 
strfilter = strfilter & " And dataFim > Now()"
Now() includes time of day and using it when you mean Date() can result in inaccurate results.
 
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 ?
 
strfilter = strfilter & " And dataFim > DateAdd('h',1, Now())"
 
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

Back
Top Bottom