Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

iif statement 1

Status
Not open for further replies.

itechC

Programmer
Feb 13, 2003
71
CA
Hey,

I was wondering if anyone can tell why my iif statement isn't working. I am trying to pull a report based on monday threw thursday and if the user clicks on include friday and saturday in my form it will include the whole week.

IIf([tblCriterias]![FriSat]=True,(Weekday([Date]))>=2 And (Weekday([Date]))<=5)
 
Well, and a programmer should know this, IIf, an if statement, takes 3 parameters - condition, true, false. If you search on IIF in Access help, you'll see the syntax. Your IIF is built wrong.
 
i have an else statement and you don't necessarily need an else statement for your if to work.

IIf([tblCriterias]![FriSat]=False,(Weekday([Date]))=2,(Weekday([Date]))=3)
 
There is no "Else" in an IIf statement. As fneily said, your statement is built incorrectly, specifically

- It is not of the form IIf(Condition, ResultIfTrue, ResultIfFalse)

- The "results" that you do have (e.g. Weekday([Date])=2), are logical comparisons that will return TRUE or FALSE. They WILL NOT assign a value of "2" to Weekday([Date])

- If you do not include the third argument then it defaults to NULL.
 
This does not seem to make any sense.
1) If you have a field named "Date" that is a bad name since it is a Reserved word.
2) (Weekday([Date]))=2
and
(Weekday([Date]))=3
Will return true or false
Not sure what you are expecting to happen
ex. ?weekday(date()) = 3
False

How are you using this iif.
 
MajP

It might make sense if it's something like
Code:
WHERE IIf(NOT [tblCriterias]![FriSat], _
          Weekday([Date]) = 2, _
          Weekday([Date]) = 3 )
But that would be neater as
Code:
WHERE Weekday([Date]) = IIf(NOT [tblCriterias]![FriSat], 2, 3)
 
Golom,

I tried your code and it works fine but what if i wanted the part that returns true to display all days of the week except friday and saturday and the part that returns false to return all days of the week.
 
Code:
WHERE [tblCriterias]![FriSat] 
   OR 
      (NOT [tblCriterias]![FriSat] AND WeekDay([Date]) NOT IN (6, 7))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top