Results 1 to 5 of 5
  1. #1
    Eddy Sincere is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Location
    Carson City, NV
    Posts
    114

    Query IIF expression that displays either text or a number in percent format

    I have an IIF expression that returns one of two values: 1) text or, 2) a calculation that I want displayed in a percent format. My problem is that I can't get the calculation to display as a percent.



    Here's the IIF expression:

    E3: IIf([Qntty]/[VMDV]<1,"<1%",[Qntty]/[VMDV])

    [Qntty] = Quantity; Example: 10

    [VMDV] = Quantity; Example: 1.5

    Actual IIF Result = 6.6666...7

    Desired IIF Result = 667%


    When I add "Percent" into Properties, Format it doesn't change anything. Probably because the IIF can display a text or numerical value. Should I add something in the Criteria?

    I can post the query or DB if you'd like. Thanks in advance for any advice.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Maybe
    Code:
    E3: IIf([Qntty]/[VMDV]<1,"<1%",Format([Qntty]/[VMDV],"##.#%))
    or
    Code:
    E3: IIf([Qntty]/[VMDV]<1,"<1%",Format([Qntty]/[VMDV],"#%))
    The result of the Format() function will be a string.

  3. #3
    CJ_London is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you will have problems trying to have iif return either a text or a number - the vba interpreter will treat both as text - and you cannot format text using a control format property. However as steve suggests, you can use the format function to return a text value - you just won't be able to do any math manipulation on the result.

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Good point, Ajax. Much clearer than what I posted.

  5. #5
    Eddy Sincere is offline Competent Performer
    Windows 7 64bit Access 2013
    Join Date
    Jul 2014
    Location
    Carson City, NV
    Posts
    114
    Excellent solution. And, thanks to Ajax (Francis?) for clarifying.

    I had to make one adjustment to the expression by adding quotation marks to close the argument. Now it looks like:

    E3: IIf([Qntty]/[VMDV]<1,"<1%",Format([Qntty]/[VMDV],"#%"))

    (obscure Deadpool reference. )

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

Similar Threads

  1. Replies: 6
    Last Post: 08-09-2014, 10:09 PM
  2. Format Formula - Text as Number
    By Madmartigan in forum Queries
    Replies: 8
    Last Post: 03-04-2014, 03:23 PM
  3. Replies: 2
    Last Post: 01-28-2014, 10:13 PM
  4. Replies: 3
    Last Post: 12-21-2012, 02:27 PM
  5. Replies: 10
    Last Post: 09-21-2012, 09:00 AM

Tags for this Thread

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