Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 485
  • Last Modified:

IIF Statement in Access Query

This is what I had so far:
NewField: IIf([Field1]=True,[Field1],IIf([Field2]=True,[Field2],IIf([Field3]=True,[Field3],IIf([Field4]=True,[Field4])))))

The above query is not giving me the right answer.

I have a Access query with 5 fields and IIF statements based on the 4 fields(Field1, Field2, Field3, Field4) into Newfield.


Please see attach example in word document.

Thank you.
IIF-Multiple-Statements-in-Access-2007.d
0
Queennie L
Asked:
Queennie L
1 Solution
 
FlysterCommented:
So if any of the 4 fields are True, you want the 5th field to be True too? In that case you can use:

NewField:IIf([Field1]+[Field2]+[Field3]+[Field4]<0,"True","")

Flyster
0
 
hnasrCommented:
Try:
Newfield : Field1 AND Field2 AND Field3 AND Field4
0
 
Dale FyeCommented:
Actually, I think you mean:

NewField = [Field1] OR [Field2] OR [Field3] OR [Field4]
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
hnasrCommented:
If any member of the team has to be good to select the team, then use OR.
If each member of the team has to be good to select the team, then use AND.
0
 
clarkscottCommented:
That's why I love building coded function for this stuff.  Nested IIF's can be confusing/hard to read.

Function GetAnswer(byref field1 as Boolean, byref field2 as Boolean, byref field3 as Boolean, byref field4 as Boolean) as Boolean

if field1 = true then
     GetAnswer = field1
elseif field2 = true then
     GetAnswer = field2
elseif field3 = true then
     Getanswer = field3
elseif field4 = true then
     Getanswer = field4
end If
exit function

Now, use the function in your query:
YourAnswer= GetAnswer([field1],[field2],[field3],[field4])

Scott C
0
 
Queennie LAuthor Commented:
None of these give me what I needed.

If Field1, Field2, Field3, Field4 has "complete" then show it in Newfield else show Overdue, Assigned and if null then leave it blank.

I used the OR and AND.

Thank you.
0
 
hnasrCommented:
As you see Overdue is just mentioned in in the last comment.
What does "has complete" mean?
An example with meaningful data would speed up the solution.
List variations of values and the required value of the IIF statement.
0
 
Leo AlexanderCommented:
If Field1, Field2, Field3, Field4 has "complete" then show it in Newfield else show Overdue, Assigned and if null then leave it blank.

If Field1 ="Complete" Then
  If Field2 = "Complete" Then
    If Field 3="Complete" Then
      If Field 4= "Complete" Then
     
         Newfield = "Complete/Whatever you want"

         else
   
          Newfield = "Overdue"
          Exit Sub
End If
End If
End If
End If
0
 
TSIsolutionsCommented:
Hi there,

If you are using an access  query and not VBA (in order to create Case of If statements) maybe you should look into using the switch function:

ex: Switch (SupplierID=1, "IBM", SupplierID=2, "HP", SupplierID=3, "Nvidia")
0
 
Queennie LAuthor Commented:
Thank you.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now