The result of iif equation in query appairs 0 and -1

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ahmedamer
    New Member
    • Jan 2014
    • 6

    The result of iif equation in query appairs 0 and -1

    After using iif equation in query (access 2013)to add new field, the result is -1 & 0
    the equation is result:
    Code:
    iif([fieldname]=yes, yes, no]
    I want the result to appear yes or no (or check box)
    Last edited by zmbd; Jan 4 '14, 08:02 AM. Reason: [OP{Clarify the situation}][Z{Please use the [CODE/] button to format posted code script and formated text - Please read the FAQ}]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    In a yes/no field, and in VBA, the True/Yes = -1 and False/No = 0
    What you have
    Code:
    iif([fieldname]=yes, yes, no]
    is returning the values
    I would suggest is placing quotes:
    Code:
    iif([fieldname]=yes, "yes", "no"]
    which will return the string

    Now remember, this will be a string value for the calculated field.

    Comment

    • Ahmedamer
      New Member
      • Jan 2014
      • 6

      #3
      Thank you very much. the problem is solved. but another problem appeared. the following equation gives errors
      Code:
      iif([fieldname]=[result],"yes", "no")
      [fieldname] is yes/no field from table source.
      [result] is a field created in query as the following
      result:
      Code:
      iif([fieldename2]=yes, "yes", "no")
      Last edited by zmbd; Jan 4 '14, 04:08 PM. Reason: [z{placed required code tags - Please do this by using the [CODE/] button}]

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        Ahmedamer

        New Question - New Thread
        For clarity; we ask that a single topic be handled per thread.
        You may link back to this thread if required for contex.

        Please, when you repost clarify the following:
        the following equation gives errors
        You do not specify the error(s) given nor the context within which the equation is used (form, query, table, vba, etc...)

        Please use the [CODE/] button to place [CODE] [/CODE] around script or formated tables.
        This is a site requirement.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          I think you need to understand that Yes, No, True & False are absolutely not the same as "Yes", "No", "True" & "False". This lack of understanding is the cause of your second question. Really, they are both centred around a single misunderstandin g.

          If you want a Yes/No value, then you probably need a numeric field. Normally, this will show as -1 and 0 if there is nothing to help it realise you want it displayed as Yes/No. Fields in tables can be specified as Yes/No, True/False or boolean. All add up to fundamentally the same thing in reality.

          If you are showing the result of a numeric calculation (or any numeric formula) in a query then you need to look at the Properties window and set the Format property to something like Yes/No. I'm not aware that you can specify a CheckBox type control for a calculated field in a query. These show when boolean fields are used though, even in a query.

          You can also, if you want to convert your usable numeric values to less usable display values, use format :
          Code:
          Format([fieldname],"Yes/No")
          My advice would be to avoid any such conversion where possible though, as it tends to lead to further problems. One of which you've stumbled over already.

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            The "yes/no" confusion (IMHO) is due to MS using that as the type-cast descriptor in the table designer. I can understand their desire; however, it might have been better to have used "true/false"

            This become very clear in the format property of the "Yes/No" type cast field where they have:
            [True/False - True]
            [Yes/No - Yes]
            [On/Off - Off]
            MS is hiding the fact that they are using the boolean -1 = true and 0 = false

            As for the conversion thing... NeoPa has a very valid point.
            Personally, I only convert these to a text string when I need a text value for a report and never anything else

            (NeoPa: Create a Yes/No field in a table, in the general tab set to "true/false", in the lookup tab, select the text box... now the field will read "true/false" or "Yes/No" - this will carry thru to the query. The combobox option is spooky to work with for these as you can really get creative and obscure (evil-laugh))

            Comment

            Working...