IIf statement

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rhonda6373
    New Member
    • Mar 2010
    • 35

    IIf statement

    Can anyone help me to break this statement down? I have basic Access skills, but this is really too advanced for me. I was trying to do a job for someone but may have to tell him I cannot do it. I am trying to understand the queries before I start trying to make changes.

    Code:
    IIf(IsNull([Forms]![Default]![st])
       ,[LL]
       ,IIf([Forms]![Default]![st]="All"
          ,[LL]
          ,IIf([Forms]![Default]![st]="Pre-Installed"
             ,1
             ,[LL])
          )
    )
    This is part of a query that the Total row = Where and the Table is a Subquery. Please let me know if you need additional information.
    Last edited by zmbd; Aug 19 '14, 12:51 PM. Reason: [Z{Please use the [CODE/] button to format posted script and formated text - Please read the FAQ}{stepped sql}]
  • twinnyfo
    Recognized Expert Moderator Specialist
    • Nov 2011
    • 3653

    #2
    Rhonda,

    What is the error (if any) that you are receiving? Based on the syntax of the statement, it looks like all should run well.

    Please let us know exactly what you are asking.

    Comment

    • jimatqsi
      Moderator Top Contributor
      • Oct 2006
      • 1288

      #3
      rhonda6373,
      All complex things are no more than a combination of simple things. Look at the documentation for the iif statement (3 parameters, returning the value of either the 2nd or 3rd, depending on the test result in parameter 1). ISNULL takes one parameter and returns a boolean.

      I often find it help to paste complex code in a text editor and add line feeds at the end of each clause or function call or ending ")"

      Only when we understand each part can we understand the whole.

      Jim

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        What it's saying is :
        Check the value of the [st] control (probably TextBox) on the [Default] form and ...
        If it is empty then use the value from [LL] (a field from the query).
        Otherwise, if it is "All" then use the value from [LL].
        Otherwise, if it is "Pre-Installed" then use the value 1.
        Otherwise use the value from [LL].

        This is an awkward way of saying :
        If [st]='Pre-Installed' then use 1 otherwise use [LL].

        In code that would be :
        Code:
        IIf(Forms!Default!st='Pre-Installed',1,[LL])
        When a value is Null and it's compared to anything else the value returned, instead of either True or False, will be Null. Null will cause the False path to be taken though, so if [st] is Null it will resolve to [LL] - just as desired.

        Comment

        • rhonda6373
          New Member
          • Mar 2010
          • 35

          #5
          Thank you all very much. This was helpful.

          The database has a drop down box (st) where the records from a subform can be filtered after making a selection and clicking Search. I was trying to change (st) from a drop down to radio buttons and was not sure how to make that change.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32633

            #6
            I can't see how that last statement ties in with this question at all. Remember, all we know is what you've told us and that doen't include much more than the single SQL statement from your first post and that st is a ComboBox control.

            Comment

            Working...