using like operator with FindFirst

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MikeyS
    New Member
    • Nov 2012
    • 3

    using like operator with FindFirst

    Hi All

    I have an unbound text box used to put in data to search through surnames activated on the onchange event. I'm using findfirst with the like operator. I can get it to work with the wildcard symbol located on both sides of the text box as shown below

    Code:
     Me.RecordsetClone.FindFirst "[Surname] like ""*" & Me.txtSearch & "*"""
    However I only want the wildcard at the end of the text box but I can't get the syntax correct as shown below:

    Code:
     Me.RecordsetClone.FindFirst "[Surname] like (me.txtSearch & " * ")"
    Any help would be appreciated

    Mike
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    I don't have the editor open right now and I'm on my way out of the office; however, your syntax appears to be off. Try the following:
    Code:
    Me.RecordsetClone.FindFirst "[Surname] like '" & me.txtSearch & "*'"
    Normally I buld these strings first and then insert them into the functions as the string are much easier to trouble shoot when you can see the resloved value.
    Last edited by zmbd; Nov 28 '12, 11:44 PM. Reason: [Z{Fixed textSearch to txtSearch in codeblock}]

    Comment

    • MikeyS
      New Member
      • Nov 2012
      • 3

      #3
      Hi zmbd

      Tried your syntax but says method or data member not found. Any other ideas we must be close

      Mike

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Did you copy z's code exactly? Because that won't work. Z used textSearch while your previous code indicated the control is actually named txtSearch.

        Comment

        • zmbd
          Recognized Expert Moderator Expert
          • Mar 2012
          • 5501

          #5
          Opps sorry... (blush)
          I just got home and logged in to see what happened.
          However, I did mention that I was on my way out-the-door :-)

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32645

            #6
            It seems you missed out the opening quote after the Like keyword. Actually, the quotes are better done as standard SQL quotes ('), but doubling the double-quotes (") works too (See Quotes (') and Double-Quotes (") - Where and When to use them) :
            Code:
            Me.RecordsetClone.FindFirst "[Surname] Like '" & Me.txtSearch & "*'"

            Comment

            • MikeyS
              New Member
              • Nov 2012
              • 3

              #7
              Thankyou everyone for your help. The final syntax got us across the line and thanks Neopa for the reference to the article as well.

              Mike

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32645

                #8
                Always a pleasure Mikey :-)

                Comment

                Working...