How to fix IIF expression

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ella Twary
    New Member
    • May 2012
    • 4

    #1

    How to fix IIF expression

    I'm trying to sum volumes in a table, however I have more than one unit of measure (liters and milliliters). I created the following in the 2007 Access Expression Builder, but when I run the query, the /1000 (to take mL to L) does not calculate.
    Code:
    CONVERT: IIf([UOM]="Milliliter*",[VOLUME]/1000,[VOLUME])
    Any suggestions on how to fix?!
    Last edited by NeoPa; May 23 '12, 01:13 AM. Reason: You must use the CODE tags.
  • mshmyob
    Recognized Expert Contributor
    • Jan 2008
    • 903

    #2
    Maybe a typo. Why do you have a caret after Milliliter?

    cheers,

    Comment

    • Ella Twary
      New Member
      • May 2012
      • 4

      #3
      Its not a caret, its a * wildcard, in case there is anything after milliliter.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        If it's a wildcard character then you need to use "Like" rather than "=".

        Comment

        • mshmyob
          Recognized Expert Contributor
          • Jan 2008
          • 903

          #5
          Then like Neo says you cannot use an equal sign. The qual sign will look for a literal match and by your answer you will never find a record in your table where the column UOM="Milliliter *".

          Change the equal sign to the word LIKE as indicated by Neo and see if that helps you.

          cheers,

          Comment

          • Ella Twary
            New Member
            • May 2012
            • 4

            #6
            Code:
            CONVERT: IIF ([UOM]LIKE"Milliliter*",[VOLUME])/1000,[VOLUME])
            I'm getting an error stating that the expression contains invalid syntax, or you need to enclose your text data in quotes.
            Now what?

            Thanks for your help mshmyob and Neo
            Last edited by NeoPa; May 23 '12, 09:42 PM. Reason: You must use the CODE tags.

            Comment

            • mshmyob
              Recognized Expert Contributor
              • Jan 2008
              • 903

              #7
              That is because there is no statement or expression called [UOM]LIKE"Milliliter *".

              Try adding proper spacing like so
              Code:
              [UOM] LIKE "Milliliter*"
              Also I noticed you are missing an opening bracket: ie: you have one "(" and two ")".

              cheers,
              Last edited by NeoPa; May 23 '12, 09:43 PM. Reason: You must use the CODE tags.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32669

                #8
                How to fix IIF expression

                Of course, it may be simpler and more reflective of the logic if you used :
                Code:
                CONVERT: [Volume] / IIf([UOM] Like 'Millilitre*',1000,1)
                As well as reflecting the proper spelling of Millilitre ;-)

                Comment

                • Ella Twary
                  New Member
                  • May 2012
                  • 4

                  #9
                  Halleluia! Thank you NeoPa

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32669

                    #10
                    Glad to help Ella :-)

                    PS. A new discussion was triggered from this thread (Discussion: Spelling of Litre).
                    Last edited by NeoPa; May 24 '12, 08:54 AM. Reason: Added PS.

                    Comment

                    Working...