Multiple criteria into one field in a query?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dakota1606
    New Member
    • Jan 2010
    • 12

    Multiple criteria into one field in a query?

    In a MS Access query it's straight forward when you want to return record number 100 as in:
    Code:
    SELECT *
    FROM Depreciation
    WHERE (((Depreciation.ID)=300));
    Is it possible, in this instance of the query, to ask for and return record number 100 and 135 and 206 and 310 and so on?

    If the answer is "yes", how is it done?

    dakota1606
    Last edited by NeoPa; Feb 5 '10, 07:16 PM. Reason: Please use the [CODE] tags provided
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    Yes
    Code:
    SELECT *
    FROM Depreciation
    WHERE (((Depreciation.ID)=300) OR ((Depreciation.ID)=213) OR ((Depreciation.ID)=217)));

    Comment

    • dakota1606
      New Member
      • Jan 2010
      • 12

      #3
      Excellent! That works great. Now all I have to do if figure out how to pass the criteria to the query from a control on a Form.

      Any ideas?

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32656

        #4
        A more flexible way would be something like :
        Code:
        SELECT *
        FROM   [Depreciation]
        WHERE  [ID] In(100,135,206,310)
        Originally posted by dakota1606
        Now all I have to do if figure out how to pass the criteria to the query from a control on a Form.

        Any ideas?
        Not in this thread please. Ask a new question in a new thread. You may post a link to this one from there (or even vice-versa) if you think it would help.

        Comment

        • TheSmileyCoder
          Recognized Expert Moderator Top Contributor
          • Dec 2009
          • 2322

          #5
          WHERE [ID] In(100,135,206, 310)
          I did not know that...thanks.. .

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32656

            #6
            I sort of figured from your post Smiley ;)

            That said, don't think you're the only one here learning things from other experts. I do it all the time. This is actually a great place for members and experts alike to pick up all sorts of tips and tricks.

            Comment

            • dakota1606
              New Member
              • Jan 2010
              • 12

              #7
              Originally posted by NeoPa
              A more flexible way would be something like :
              Code:
              SELECT *
              FROM   [Depreciation]
              WHERE  [ID] In(100,135,206,310)
              Not in this thread please. Ask a new question in a new thread. You may post a link to this one from there (or even vice-versa) if you think it would help.
              TheSmileyOne's solution was workable but cumbersome for use on my form. But this....... this is awesome. I can make one entry or a dozen with no problem. Thanks huge!

              dakota1606

              Comment

              • dakota1606
                New Member
                • Jan 2010
                • 12

                #8
                Originally posted by TheSmileyOne
                I did not know that...thanks.. .
                I appreciate your answer earlier. I just wanted you to know that your's worked, but NeoPa's answer is much more flexible and less cumbersome. This is a great learning place.

                dakota160

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32656

                  #9
                  I'm pleased you liked it :)

                  Other possibilities in SQL can be found in the Help. For this you need to navigate in Help for "Microsoft Jet SQL". It's hard to find without knowing where to look, but there's some good stuff in there if you can find it.

                  Comment

                  Working...