Using .Find with multiple search criteria

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • salzan
    New Member
    • Feb 2008
    • 38

    Using .Find with multiple search criteria

    I have this code:

    strAny = "[YearId] = " & rsTemp!YearId
    rsPerm.Find strAny

    and it works. However, when I do the following it doesn't

    strAny = "[YearId] = " & rsTemp!YearId & " AND " & _
    "[DeptId] = " & rsTemp!DeptId & " AND " & _
    "[CatId] = '" & rsTemp!CatId & "'"
    rsPerm.Find strSQL

    Can anyone tell me what I'm doing wrong? I should add YearId and DeptId are numeric and CatId is String.

    Greatly appreciated.
    Salzan
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    Originally posted by salzan
    I have this code:

    strAny = "[YearId] = " & rsTemp!YearId
    rsPerm.Find strAny

    and it works. However, when I do the following it doesn't

    strAny = "[YearId] = " & rsTemp!YearId & " AND " & _
    "[DeptId] = " & rsTemp!DeptId & " AND " & _
    "[CatId] = '" & rsTemp!CatId & "'"
    rsPerm.Find strSQL

    Can anyone tell me what I'm doing wrong? I should add YearId and DeptId are numeric and CatId is String.

    Greatly appreciated.
    Salzan
    Salzan,
    Try changing this: rsPerm.Find strSQL

    To this: rsPerm.Find strAny

    Comment

    • salzan
      New Member
      • Feb 2008
      • 38

      #3
      Sorry that was a typo - it's strAny. The variable name is not it.

      Comment

      • FishVal
        Recognized Expert Specialist
        • Jun 2007
        • 2656

        #4
        Hi, Salzan.

        Do you mean ADODB.Recordset ?
        If so then this may give an answer to your question.

        Regards.
        Fish

        Comment

        • puppydogbuddy
          Recognized Expert Top Contributor
          • May 2007
          • 1923

          #5
          Hi Fish,

          And this link compares the Find methods of DAO with ADO.........

          Comment

          • salzan
            New Member
            • Feb 2008
            • 38

            #6
            I should have specify that I'm using ADO Recordset. The articles didn't help. My problem is with the criteria string. When I specify only one criteria it works but when I specify multiple criteria with AND operator it give me an error message "arguments are of the wrong type, are out of acceptable range, or are in conflict with one another". I've checked the types of the arguments and they're correct. I don't know what else to search.

            Thanks you for your help.
            Salzan

            Comment

            • puppydogbuddy
              Recognized Expert Top Contributor
              • May 2007
              • 1923

              #7
              Originally posted by salzan
              I should have specify that I'm using ADO Recordset. The articles didn't help. My problem is with the criteria string. When I specify only one criteria it works but when I specify multiple criteria with AND operator it give me an error message "arguments are of the wrong type, are out of acceptable range, or are in conflict with one another". I've checked the types of the arguments and they're correct. I don't know what else to search.

              Thanks you for your help.
              Salzan
              Try it this way and see if it helps:

              strAny = "[YearId] = " & rsTemp!YearId & _
              " AND [DeptId] = " & rsTemp!DeptId & _
              " AND [CatId] = '" & rsTemp!CatId & "'"

              Comment

              • Scott Price
                Recognized Expert Top Contributor
                • Jul 2007
                • 1384

                #8
                According to the Access help file, the .Find method of the ADO recordset only supports one column searches. In other words, you are out of luck trying to set multiple column criteria!

                In the VBA code editor window, position your cursor in the word Find and press F1, this brings up the help file with this specific information.

                Regards,
                Scott

                Comment

                • salzan
                  New Member
                  • Feb 2008
                  • 38

                  #9
                  THANK YOU ALL. Atleast I know I'm not doing it wrong. I think I'll create a compound column, concatenate the values together, and search against it. It should accomplish what I'm after.

                  Comment

                  Working...