Using combo box to control query / filter results

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TomM484
    New Member
    • Jun 2013
    • 3

    Using combo box to control query / filter results

    I am trying to use a combo box (named GTLT or "greater than less than") to sort my results based on if the Formula Weight ([FW]) is greater than or less than the PointValue given in another text box.

    It seems that I am having some trouble using an iif statement here, because it will not let me change the query criteria based on if the GTLT = "greater than" or not. Here is what I have written :

    IIf([Forms]![Search Type]![GTLT]="greater than",([CompoundID]![FW]>=[Forms]![Search Type]![PointValue]),([CompoundID]![FW]<[Forms]![Search Type]![PointValue]))

    All I want it to do, is take the value given by PointValue, and return all results that are either greater than it (if the statement is true), or less than it (if the statement is false). Access does not seem to like this. Please let me know if you have any ideas.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Please show us the full SQL.

    Comment

    • TomM484
      New Member
      • Jun 2013
      • 3

      #3
      This is what MS Access gave me in SQL View for the query in question:

      Code:
      SELECT CompoundID.CpdID, CompoundID.sortas, CompoundID.CAS, CompoundID.type, CompoundID.FW, CompoundID.BP
      FROM CompoundID
      WHERE (((CompoundID.FW)=IIf([Forms]![Search Type]![GTLT]="greater than",([CompoundID]![FW]>[Forms]![Search Type]![PointValue]),([CompoundID]![FW]<[Forms]![Search Type]![PointValue]))));

      Tom
      Last edited by Rabbit; Jun 11 '13, 09:55 PM. Reason: Please use code tags when posting code.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Please use code tags when posting code.

        It makes no sense to see if FW is equal to true/false. Which is what your IIf function returns. Just have it return the trues.

        Comment

        Working...