1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Access - Nested IIf Statements

Discussion in 'Business Applications' started by Devan, Feb 16, 2005.

Thread Status:
Not open for further replies.
Advertisement
  1. Devan

    Devan Thread Starter

    Joined:
    Feb 10, 2005
    Messages:
    24
    I am looking for an example of how to do a nested iif statement in access. I have 7 separate returns from a field in the database I am using, if I get e.g 5_Bro returned I want to enter brown, if I get 6_Yel I want to enter Yellow automatically. I can get this to work if I do separate If statements but I only want to only have 1 coloum which returns the correct colour. Or any other solution to this problem if not an if statement
     
  2. coachdan32

    coachdan32

    Joined:
    Nov 13, 2003
    Messages:
    1,021
    The second IIf goes in place of the Else condition.

    Example:
    =If([field1]=1,1,"")
    Nested:
    =If([field1]=1,1,If([field1]=2,2,""))

    And so on...There is a limit on the level of nestings - not sure of how many though.
     
  3. WhitPhil

    WhitPhil Gone but never forgotten Trusted Advisor

    Joined:
    Oct 4, 2000
    Messages:
    8,684
  4. Devan

    Devan Thread Starter

    Joined:
    Feb 10, 2005
    Messages:
    24

    Thanks so much, looks so simple now I have the answer. It works find I just tested it with a couple of options. I may have a look at the switch statement as welll
     
  5. HeavyBall

    HeavyBall

    Joined:
    Oct 29, 2004
    Messages:
    72
    select may even work better:

    Select case [oldcolorfield]
    Case brn
    [newcolorfield] = "brown"
    Case yel
    [newcolorfield] = "yellow"
    End Select
     
  6. coachdan32

    coachdan32

    Joined:
    Nov 13, 2003
    Messages:
    1,021
    I agree with HeavyBall, a case select would seem to be a better fit.
     
  7. Devan

    Devan Thread Starter

    Joined:
    Feb 10, 2005
    Messages:
    24
    Thank you I will try this out as well, always good to a few options to hand!
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/331268

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice