![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
=Date()-5,IIf(Format(Now(),"DDDD")in ("Thursday","Friday") =Date()-3)) |
#2
| |||
| |||
|
|
Hello all; Access 2000 sql server backend. I am trying to implement dynamic criteria into a query instead of hard- coding a range. It is a date/time field. I want the query to retrieve a range of data based on what day of the week it is. I tried the following in the criteria of this date/time field: * * *IIf(Format(Now(),"DDDD")in ("Monday","Tuesday","Wednesday") * * *>=Date()-5,IIf(Format(Now(),"DDDD")in ("Thursday","Friday") * * *>=Date()-3)) The query ignores it and retrieves all the data. If I hard code it, it will work, like the following: >=Date()-5 Anybody know why my "IIF" doesn't work in the query criteria? What can I do to make it work? Thanks in advance for any assistance. Tony |
#3
| |||
| |||
|
|
How are you calling your query? From vba code? Can you use: If Format(Now(),"DDDD")in ("Monday","Tuesday","Wednesday") Then * *DoCmd.RunSQL "Select....[your stuff]...>=#" & Date()-5 & "#" Else * *DoCmd.RunSQL "Select....[your stuff]...>=#" & Date()-3 & "#" Endif Fred On Apr 5, 5:16*am, Tony_E <bluestealt... (AT) hotmail (DOT) com> wrote: Hello all; Access 2000 sql server backend. I am trying to implement dynamic criteria into a query instead of hard- coding a range. It is a date/time field. I want the query to retrieve a range of data based on what day of the week it is. I tried the following in the criteria of this date/time field: * * *IIf(Format(Now(),"DDDD")in ("Monday","Tuesday","Wednesday") * * *>=Date()-5,IIf(Format(Now(),"DDDD")in ("Thursday","Friday") * * *>=Date()-3)) The query ignores it and retrieves all the data. If I hard code it, it will work, like the following: >=Date()-5 Anybody know why my "IIF" doesn't work in the query criteria? What can I do to make it work? Thanks in advance for any assistance. Tony- Hide quoted text - - Show quoted text - |
#4
| |||
| |||
|
|
On Apr 5, 10:52 am, "zuckerm... (AT) gmail (DOT) com"<zuckerm... (AT) gmail (DOT) com wrote: How are you calling your query? From vba code? Can you use: If Format(Now(),"DDDD")in ("Monday","Tuesday","Wednesday") Then DoCmd.RunSQL "Select....[your stuff]...>=#"& Date()-5& "#" Else DoCmd.RunSQL "Select....[your stuff]...>=#"& Date()-3& "#" Endif Fred On Apr 5, 5:16 am, Tony_E<bluestealt... (AT) hotmail (DOT) com> wrote: Hello all; Access 2000 sql server backend. I am trying to implement dynamic criteria into a query instead of hard- coding a range. It is a date/time field. I want the query to retrieve a range of data based on what day of the week it is. I tried the following in the criteria of this date/time field: IIf(Format(Now(),"DDDD")in ("Monday","Tuesday","Wednesday") =Date()-5,IIf(Format(Now(),"DDDD")in ("Thursday","Friday") =Date()-3)) The query ignores it and retrieves all the data. If I hard code it, it will work, like the following:>=Date()-5 Anybody know why my "IIF" doesn't work in the query criteria? What can I do to make it work? Thanks in advance for any assistance. Tony- Hide quoted text - - Show quoted text - Thanks for the reply. I am running this from a query object--utilizing the criteria "box" in the field column. That is the way I am trying to do it because most of the access programs here don't utilize vba modules |
#5
| |||
| |||
|
|
You can try the following in a query. Field: SomeDateField Criteria: >= Date() - IIF(WeekDay(Date(),1) in (2,3,4),5,3) If you insist on using the format function. *Then Criteria: >= Date() - IIF(Format(Now()),"DDDD") IN ("Monday","Tuesday","Wednesday"),5,3) John Spencer Access MVP 2002-2005, 2007-2010 The Hilltop Institute University of Maryland Baltimore County On 4/5/2011 10:57 AM, Tony_E wrote: On Apr 5, 10:52 am, "zuckerm... (AT) gmail (DOT) com"<zuckerm... (AT) gmail (DOT) com wrote: How are you calling your query? From vba code? Can you use: If Format(Now(),"DDDD")in ("Monday","Tuesday","Wednesday") Then * * DoCmd.RunSQL "Select....[your stuff]...>=#"& *Date()-5& *"#" Else * * DoCmd.RunSQL "Select....[your stuff]...>=#"& *Date()-3& *"#" Endif Fred On Apr 5, 5:16 am, Tony_E<bluestealt... (AT) hotmail (DOT) com> *wrote: Hello all; Access 2000 sql server backend. I am trying to implement dynamic criteria into a query instead of hard- coding a range. It is a date/time field. I want the query to retrieve a range of data based on what day of the week it is. I tried the following in the criteria of this date/time field: * * * IIf(Format(Now(),"DDDD")in ("Monday","Tuesday","Wednesday") * * * >=Date()-5,IIf(Format(Now(),"DDDD")in ("Thursday","Friday") * * * >=Date()-3)) The query ignores it and retrieves all the data. If I hard code it, it will work, like the following:>=Date()-5 Anybody know why my "IIF" doesn't work in the query criteria? What can I do to make it work? Thanks in advance for any assistance. Tony- Hide quoted text - - Show quoted text - Thanks for the reply. I am running this from a query object--utilizing the criteria "box" in the field column. That is the way I am trying to do it because most of the access programs here don't utilize vba modules- Hide quoted text - - Show quoted text - |
#6
| |||
| |||
|
|
I am trying to implement dynamic criteria into a query instead of hard- coding a range. It is a date/time field. I want the query to retrieve a range of data based on what day of the week it is. I tried the following in the criteria of this date/time field: IIf(Format(Now(),"DDDD")in ("Monday","Tuesday","Wednesday") =Date()-5,IIf(Format(Now(),"DDDD")in ("Thursday","Friday") =Date()-3)) The query ignores it and retrieves all the data. |
#7
| |||
| |||
|
#8
| |||
| |||
|
|
According to the Help file, the precedence of boolean operators is Not, And, Or, Xor, Eqv, Imp Doesn't that mean that WHERE condition1 OR condition2 AND condition 3 will always be evaluated at WHERE condition1 OR (condition2 AND condition 3) |
#9
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |