Results 1 to 11 of 11
  1. #1
    LanieB is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    54

    Iff Statement -- I need it to do two different things...


    So I have MANY reports that are showing scores for what our employees got on their audits... my question is...

    Sometimes the points are N/A -- but I do not know how to tell access to show me N/A when it see 0/0 but show 0% when it sees 0/10. Right now I have it as...

    Overall Score: IIf([Points Available]=0,0, [Points Earned]/[Points Available])
    I had to write that because it would give me an error when it tried to divide anything by 0. But the problem is on their reports sometime there was 0 available and 0 earned and it still shows up as a 0%. Is there any iff statement in the world of access that can recognize 0/0 = N/A but 0/any number = 0%?

  2. #2
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Will this work?

    Code:
    IIf([Points Earned]=0 AND [Points Available]=0,"N/A",IIf([Points Available]=0,0, [Points Earned]/[Points Available]))

  3. #3
    LanieB is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    54
    Thank you!! It does work But now I am unable to set the format to show as a percentage. Is there another way I would be able to display the results in percent form?

  4. #4
    LanieB is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    54
    I tried to set the format in both the query and report. But neither will work.

  5. #5
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Since the function can return text ("N/A") or a number that is why you cannot apply a format.

    One alternative is to not return "N/A", but rather just an empty field (NULL). With that you will be able to apply the format when a numerical value is returned.

    IIf([Points Earned]=0 AND [Points Available]=0,NULL,IIf([Points Available]=0,0, [Points Earned]/[Points Available]))

  6. #6
    LanieB is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Nov 2011
    Posts
    54
    You are my favorite person in the whole world...

    THANK YOU SO MUCH!

  7. #7
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    You're welcome!

  8. #8
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Hey, what about me???

    I did all the heavy lifting (or was it thinking?)..

    jzwp11 just made it work when I wasn't looking...



    OK, here is the best of both worlds:
    IIf([Points Earned]=0 And [Points Available]=0,"N/A",IIf([Points Available]=0,0,Format([Points Earned]/[Points Available],"percent"))

  9. #9
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    Steve,

    I was messing around with the format() function in an attempt to keep the "N/A" but was unsuccessful. I got that one figured out.

    Thanks!

  10. #10
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by jzwp11 View Post
    Steve,

    I was messing around with the format() function in an attempt to keep the "N/A" but was unsuccessful. I got that one figured out.

    Thanks!
    I used an three unbound controls on an unbound form and it seemed to return the correct values....

    time

  11. #11
    jzwp11 is offline VIP
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jun 2010
    Location
    Dayton, OH
    Posts
    2,901
    I was just not using the format() function correctly; I do not use it much in my applications.

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

Similar Threads

  1. Strange things happening to Access
    By accessnewb in forum Access
    Replies: 5
    Last Post: 07-29-2011, 05:57 AM
  2. New server breaks things
    By blinks in forum Access
    Replies: 1
    Last Post: 03-05-2011, 01:52 AM
  3. Opening a form with openargs and things
    By mwabbe in forum Forms
    Replies: 5
    Last Post: 09-29-2010, 11:01 AM
  4. Things moving around on my form
    By jlm722 in forum Forms
    Replies: 0
    Last Post: 09-30-2009, 03:34 PM
  5. Replies: 2
    Last Post: 09-01-2006, 04:03 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