Results 1 to 15 of 15
  1. #1
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476

    Using the IIf Function?

    Can the IIf Function be used in referencing then more than 1-fld? What do I mean? In my MLB dbs I have the following flds:


    - HmRd: Either "H" for Home games or "R" for Road Games.
    - Team
    - Score
    - AResults: "W" = win, "L" = Lost
    - W: IIf([AResults]="W",1,0) - that works
    - L: IIf([AResults]="L",1,0) - that works
    - HW: IIf([AResults]="W" & [HmRd]="H",1,0) that DOESN'T work
    - RW: IIf([AResults]="W" & [HmRd]="R",1,0) that DOESN'T work

    Does anyone follow my question. Is the IIf Function exculsively just involves 1-fld in it's statement or can multiply flds be in an IIf statement?

    Thanks

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You can test multiple fields. You would separate each with And or Or rather than &, which is a on concatenation operator.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Thanks pb Ok, I got the "And" concept, but not the "Or". In my NHL dbs the 'W' fld gets a 1 if the AResults fld either has a "W" or a "W\SO"

    I tried:
    - W: Iif([AResults]="W",1,0" Or "W\SO",1,0)
    - W: Iif([AResults]="W",1,0" Or Iif[AResults]="W\SO",1,0)

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    No, like

    HW: IIf([AResults]="W" And [HmRd]="H",1,0)

    In that situation you use And or Or as appropriate to the logic you need (both criteria must be met or either one).
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Why isn't this expression working? I want a 1 in the 'W' field/column if eithr in thhe AResults field has either a "W" or a "W\SO"

    W: IIf([AResults]="W", Or [AResluts]="W\SO",1,0)

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You added a comma in the middle of the test.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    W: IIf([AResults]="W" Or IIF[AResluts]="SOW",1,0) Still doesn't work

  8. #8
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Why when I have, W: IIf([AResults]="W" Or IIF[AResluts]="SOW",1,0) I also have a "1" in the OTL fld/column?
    AND
    When I have, OTL: IIf([AResults]="OTL" Or "SOL",1,0) I'm also getting a "1" in the fld/column?

    BTW: just for clairity, I changed "W\SO" to "SOW"

    NHL 101
    You can have 3-types of results per game
    - W: Win
    - L: Lost
    - OTL: Overtime Lost

    I chose to add 2-more Results:
    - SOW: Shoot Out Win which I can write an IIf statement in my SOW fld/column - SOW: IIf([AResults]="SOW",1,0)
    - SOL: Shoot Out Lostwhich I can write an IIf statement in my SOL fld/column - SOL: IIf([AResults]="SOL",1,0)

    My problem I'm encounting is, in the "W" (Win) fld/column I'm trying to set up an IIf statement whereby a "1" is entered in the "W" fld/column if the AResults fld/column either as a, "W" or a "SOW"

    Likewise with the "OTL" fld/column, in the "OTL" (Overtime Lost) fld/column I'm trying to set up an IIf statement whereby a "1" is entered in the "OTL" fld/column if the AResults fld/column either as a, "OTL" or a "SOL"

    I don't know if/how an IIf statement can be written with more then one value in a fld?

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    You're not repeating the field:

    OTL: IIf([AResults]="OTL" Or "SOL",1,0)

    would be

    OTL: IIf([AResults]="OTL" Or [AResults]= "SOL",1,0)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Thanks Paul...

  11. #11
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Paul,
    Somthing still isn't right. with these 2-expressions I'm getting a "1" in both the 'HW' Fld & the 'AW' fld when in the 'AResuults' field is "W"...?

    HW: IIf([AResults]="W" Or [AResults]="SOW" And [HWAW]="H",1,0)
    AW: IIf([AResults]="W" Or [AResults]="SOW" And [HWAW]="A",1,0)

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    When you mix And & Or, you should add parentheses to clarify the desired logic:

    HW: IIf(([AResults]="W" Or [AResults]="SOW") And [HWAW]="H",1,0)
    HW: IIf([AResults]="W" Or ([AResults]="SOW" And [HWAW]="H"),1,0)

    More simply:

    (A And B) Or C
    A And (B Or C)

    See how the logic can change? You don't want Access applying it's own.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Paul,
    Somthing still isn't right. with these 2-expressions I'm getting a "1" in both the 'HW' Fld & the 'AW' fld when in the 'AResuults' field is "W"...?

    HW: IIf([AResults]="W" Or [AResults]="SOW" And [HWAW]="H",1,0)
    AW: IIf([AResults]="W" Or [AResults]="SOW" And [HWAW]="A",1,0)

  14. #14
    djclntn is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2011
    Posts
    476
    Sorry, I DID NOT men to repost!

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    Does that mean it's working now?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Need help with IIF function
    By RazMan in forum Access
    Replies: 4
    Last Post: 10-28-2010, 12:07 PM
  2. Help with AVG function
    By techexpressinc in forum Reports
    Replies: 1
    Last Post: 03-23-2010, 07:47 AM
  3. Function Help
    By th3spankst3r in forum Programming
    Replies: 12
    Last Post: 03-22-2010, 12:41 PM
  4. Want function to get current function name
    By Davis DeBard in forum Programming
    Replies: 2
    Last Post: 08-13-2009, 05:02 AM
  5. Is there a function to do this....
    By Nowherefast in forum Access
    Replies: 2
    Last Post: 12-31-2008, 08:08 AM

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