Results 1 to 6 of 6
  1. #1
    dharsh is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    19

    IIf Statement

    In my table I have the following 4 fields with the associated date field:
    Bronze: 11/1/2013
    Silver: 5/1/2014
    Gold: 11/1/2014
    Platinum: 5/1/2015



    I am trying to calculate a value based on comparing the current date to the dates in these fields. I am using the below formula. However, using 6/27/2013 as the current date, my formula keeps resulting in "Bronze" when it should result in "Standard" Am I doing something wrong?

    =IIf(Date()<[Bronze],"Standard",IIf((Date()>=[Bronze]) And (Date()<[Silver]),"Bronze",IIf(Date()>=[Silver] And Date()<[Gold],"Silver",IIf(Date()>=[Gold] And Date()<[Platinum],"Gold","Platinum"))))

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Why not use a Select Case structure in a standard module for this? It would be much easier to read and maintain.

  3. #3
    dharsh is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2013
    Posts
    19
    I have never done that. Everything I have done in Access up to this point is in queries and simple formulas.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2013
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Nested IIF's are hard for me to follow, sorry. Start with a single IIF and see what the results are. That build on it when you resolve the issue.

  5. #5
    Zephyx is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Jun 2013
    Posts
    11
    I could be wrong, but it appears that you just need ) after the first [Bronze]
    so basically at the very front of your code, =IIf(Date()<[Bronze])....
    ^

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I created a table, entered the dates you provided, created a query and entered the IIF() formula, all from your post#1. When I executed the query, the result was "Standard". I made no changes to what you provided.

    I changed the date for "Bronze" to 11/1/2012 and the result was "Bronze".
    I changed the date for "Bronze" back to 11/1/2013 and the result was "Standard".

    So as far as the formula is concerned - No problems. Works for me.........

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

Similar Threads

  1. if statement in sql statement, query builder
    By 54.69.6d.20 in forum Access
    Replies: 4
    Last Post: 09-11-2012, 07:38 AM
  2. Iif statement help
    By Firefighter22 in forum Queries
    Replies: 7
    Last Post: 09-30-2011, 10:59 AM
  3. Replies: 7
    Last Post: 08-17-2011, 01:49 PM
  4. BETWEEN in a FROM Statement
    By Cyborg in forum Queries
    Replies: 6
    Last Post: 05-12-2011, 01:54 PM
  5. Need Help with SQL Statement
    By Hank44 in forum Programming
    Replies: 3
    Last Post: 11-08-2010, 05:49 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