IIf in a Query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Randey
    New Member
    • Feb 2013
    • 2

    IIf in a Query

    I am trying to get a query to return a record if an ID number is inserted in a form, otherwise to return all records if the form is blank. This is the code I am trying to use.

    Code:
    =IIf([Forms]![Form Filter]![Text20]="isnull","*",[Forms]![Form Filter]![Text20])
    I don't get an error message; however, I get nothing but a blank query every time, whether I insert an ID number or not.
    Last edited by zmbd; Nov 26 '13, 11:04 PM. Reason: [Z{Please use the [CODE/] button to format posted code/html/sql/formated text - Please read the FAQ}]
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    because it does not appear that you are actually refering to any form in your equation.

    Using parameters with queries and reports

    Comment

    • dgunner71
      New Member
      • Jun 2010
      • 110

      #3
      Randy,

      In your query, try adding a new value as such:

      Code:
      fxNewValue: IIf(nz([Forms]![Form Filter]![Text20],"")="", "*",[Forms]![Form Filter]![Text20])
      Note that I've also swapped your IsNull statement for an Nz() function.

      This will add a column in your query. The column will display an asterisk if there is no value in [Text20] or the value of [Text20] if there is.

      Gunner
      Last edited by zmbd; Nov 30 '13, 11:22 PM. Reason: [dgunner71; 32 Minutes Ago at 04:48 PM. Reason: typo ][z{placed required code tags}]

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        dgunner71:
        OP wants "otherwise to return all records if the form is blank. " as well; thus, this appears to be part of VBA code or the filter property of the form. In either case the OP-Equation still fails to refer to the form; however, because OP failed to provide enough detail as to how the equation was/is being used only a generic answer can really be provided.

        Comment

        Working...