Results 1 to 9 of 9
  1. #1
    Brian Collins is offline Novice
    Windows Vista Access 2000
    Join Date
    Oct 2010
    Posts
    8

    Another Nested IIF Query problem

    Testing for two conditions and using AND/NOT/OR

    WIPTest:

    IIF([AutoMatrix] =1 And [Status] ="Settled Adjudicated",0
    IIF([AutoMatrix] =2 Or [AutoMatrix]= 4 And [Status] Not "Settled adjudicated", 555
    IIF([AutoMatrix] =3 Or [AutoMatrix]= 5 And [Status] Not "Settled adjudicated", 999,[WIP])))

    Condition one works fine but provides the False for all other conditions.

    Am I messing the logic up? Is there an heirarchy?

    Confused



    Regards

    Brian

  2. #2
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    I think you're missing some commas:

    Code:
     
    IIF([AutoMatrix] =1 And [Status] ="Settled Adjudicated",0,
    IIF([AutoMatrix] =2 Or [AutoMatrix]= 4 And [Status] Not "Settled adjudicated", 555,
    IIF([AutoMatrix] =3 Or [AutoMatrix]= 5 And [Status] Not "Settled adjudicated", 999,[WIP])))

  3. #3
    valbor is offline Novice
    Windows 7 Access 2007
    Join Date
    Oct 2010
    Location
    NY
    Posts
    6
    Here is the syntax which should work in my opinion:
    IIF([AutoMatrix] =1 And [Status] ="Settled Adjudicated",0,
    IIF(([AutoMatrix] =2 Or [AutoMatrix]= 4) And [Status] Not "Settled adjudicated", 555,
    IIF(([AutoMatrix] =3 Or [AutoMatrix]= 5) And [Status] Not "Settled adjudicated", 999,[WIP])))

  4. #4
    Brian Collins is offline Novice
    Windows Vista Access 2000
    Join Date
    Oct 2010
    Posts
    8
    Thanks guys,


    Slave, I missed the commas out on the post but not in the statement thanks for trying.

    Valbor - I tried using brackets to combine the OR condition

    Same result

    Condition one provides the correct result

    Remaining conditions from the false part of the function.

    Tired now will play with it tomorrow

    Many thanks

    B

  5. #5
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    I got it to work in testing using this:
    Code:
    Sub TestIIf(bSuccess1 As Boolean, bSuccess2 As Boolean, bSuccess3 As Boolean)
        MsgBox IIf(bSuccess1 = True, 0, IIf(bSuccess2 = True, 1, IIf(bSuccess3 = True, 2, "All were false")))
    End Sub
    I got the expected responses each time.

  6. #6
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    You might want to look at the "Not" usage in your code because I don't think it is working the way you expect. I would change it to "<>" and see if that works any better.

  7. #7
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Corrected code:
    Code:
    IIF([AutoMatrix] =1 And [Status] ="Settled Adjudicated",0,
    IIF([AutoMatrix] =2 Or [AutoMatrix]= 4 And [Status] <> "Settled adjudicated", 555,
    IIF([AutoMatrix] =3 Or [AutoMatrix]= 5 And [Status] <> "Settled adjudicated", 999,[WIP])))

  8. #8
    Brian Collins is offline Novice
    Windows Vista Access 2000
    Join Date
    Oct 2010
    Posts
    8
    Hi Slace,

    Well done, the <> construct works a treat.

    Although I am at a loss to why 'NOT' does not do what it says on the tin!

    Many thanks indeed.

    B

  9. #9
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Not might have worked if you had used = like:
    Code:
    IIF([AutoMatrix] =2 Or [AutoMatrix]= 4 And (NOT [Status] = "Settled adjudicated)",...,...)
    But as it was written, Access reinterpets it as:
    Code:
    IIF(NOT [AutoMatrix] =2 Or [AutoMatrix]= 4 And [Status],...,...)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Nested Query Question Access 2007
    By databased in forum Queries
    Replies: 5
    Last Post: 10-15-2010, 07:22 AM
  2. Nested IIF problems
    By Brian Collins in forum Access
    Replies: 2
    Last Post: 10-12-2010, 01:37 PM
  3. Nested Iif statement help
    By Goodge12 in forum Queries
    Replies: 6
    Last Post: 09-21-2010, 11:45 AM
  4. Returning correct rows in a join/nested query
    By goneaccessing in forum Queries
    Replies: 5
    Last Post: 03-03-2010, 12:21 PM
  5. Nested IIf query will not work
    By ddog171 in forum Queries
    Replies: 1
    Last Post: 06-20-2006, 02:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums