Results 1 to 4 of 4
  1. #1
    Join Date
    May 2006
    Posts
    25

    Unanswered: Is it possible to use If...then..elseif... in a query?

    Hello,

    I am trying to set up a query and at the moment I am using the IIf function to pull out some information. However, I really want three conditions instead of two.

    The fields I am wanting to check are: [GoldComplete], [SilverComplete], [BronzeComplete] (these fields are date fields). I want the query to check if the [GoldComplete] is NOT null, then put "Gold", if it IS null, then check the [SilverComplete] field and check if it is NULL or not. If it IS null, then put "Bronze" if it is NOT null, then put "Silver".

    Is it possible to get a query to do this, or do I have to do something more complicated?

    Regards,
    Bronwyn

  2. #2
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Yes. There are a couple of ways you can do it. One way is to just have another query based on the first one and use the expressin to test it further. The other (which is what I think you want to do) is to use the iif statement like so: Exp: IIf(Not IsNull([GoldComplete]),"Gold",IIf(IsNull([SilverComplete]),"Bronze","Silver")).

    I believe Izy likes to use the nz command so he might have some suggestions on rephrasing it using the nz.
    Last edited by pkstormy; 10-26-06 at 00:05.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  3. #3
    Join Date
    May 2006
    Posts
    25

    Thanks very much!

    That's exactly what I wanted. Thank you for your help...

  4. #4
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Glad to help! Thanks for letting me know it worked!

    FYI: I've always had problems with the ) and , in working with these but after a few tries, I get it to finally work.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •