Results 1 to 12 of 12
  1. #1
    JimMinard is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Posts
    7

    Conditional iif statement not returning desired values

    Hello,
    I need help with an iif statement, =IIf([OverAllScore_2]>=85,"A",IIf([OverAllScore_2]>=70,"B",IIf([OverAllScore_2]>=50,"C",IIf([OverAllScore_2]<50,"D"))))


    I am trying to assign a letter grade based on the value of [OverAllScore_2]... No matter what the value of [OverAllScore_2] is, the statement only returns a "D" for the letter grade. Any ideas on what is wrong?

  2. #2
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Usually, an IIF statement has 3 parts, but when you nest them like this, your last one doesn't. I think I would write it as
    =IIf([OverAllScore_2]>=85,"A",IIf([OverAllScore_2]>=70,"B",IIf([OverAllScore_2]>=50,"C","D"))) although not sure because 100 is greater than 50 so potentially it could return C for 100. However, it works for me as a textbox control source on a form.

    Also, where are you putting/using this? You don't say if it's a query or form control or what.
    Last edited by Micron; 04-30-2019 at 08:02 PM. Reason: clarification
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    JimMinard is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Posts
    7
    Hi – Thanks for getting back to me. I tried putting it in a text box on a form just to see if it works. I tried your suggestion but no dice…same issue.

  4. #4
    JimMinard is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Posts
    7
    I also tried it in a calculated field in the data table... Same problem, it only shows the D

  5. #5
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    I tried putting it in a text box
    That's of little help. You put it where in a control?? Control source? Default value?
    The expressions or functions you can put in a table field are quite limited, and this isn't one of them so forget that idea.

    Click image for larger version. 

Name:	A.jpg 
Views:	9 
Size:	2.1 KB 
ID:	38250 Click image for larger version. 

Name:	B.jpg 
Views:	9 
Size:	2.1 KB 
ID:	38251
    I don't have a field named OverAllScore_2 so I have 2 textboxes on a test form; one named OverAllScore_2. The second textbox has the expression I posted.
    While it may not relate to where your expression is being used (which by the way you didn't answer) it does seem to prove that it correctly evaluates as written.
    These images seem to indicate that.

  6. #6
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I would do this calculation in a query.......
    Attached Files Attached Files

  7. #7
    JimMinard is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Posts
    7
    I put a text box on the form and just tried it in a calculated field in the table... It still only shows the D.

  8. #8
    JimMinard is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Posts
    7
    Thanks Steve - Thats not quite hat I'm looking for unless I'm not interpreting your suggestion correctly.

  9. #9
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Maybe you'll have to post your db as I don't seem to be making any progress this way. I've asked twice how/where you're putting it in a textbox, plus I've already stated that such an expression will not work in a table, yet you're repeating the same information.

  10. #10
    JimMinard is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Posts
    7
    I think I found the root of the problem. My calculated field was formated as % & not as a number. I should be able to carry on. Thanks for all your efforts. Jim

  11. #11
    JimMinard is offline Novice
    Windows 10 Access 2016
    Join Date
    Apr 2019
    Posts
    7
    Hi Micron, I'm quite new at using ACCESS. Thanks for your patience. I was connecting the data to the text box through the Property Sheet and selecting the [OVERALLSCORE_2 field] through Control Source. It seems that the proplem was the fact that I had the data formatted as a percent & not as a number. Thanks for your help.

  12. #12
    Micron is offline Very Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    13,372
    Glad you solved it. Good luck with your project.

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

Similar Threads

  1. Iif statement in query returning ID number
    By Kelsallison in forum Queries
    Replies: 5
    Last Post: 06-22-2018, 03:54 PM
  2. Replies: 3
    Last Post: 03-14-2018, 01:53 PM
  3. Access Query not returning desired records
    By NaomiC in forum Queries
    Replies: 2
    Last Post: 01-10-2015, 01:18 PM
  4. Replies: 7
    Last Post: 01-11-2012, 12:24 PM
  5. IIF Statement Returning #Error
    By DrDefpoints in forum Queries
    Replies: 6
    Last Post: 05-26-2011, 12:25 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