Search code does not work

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Pranish01
    New Member
    • Jun 2014
    • 5

    Search code does not work

    I have break VBA code but it does not work

    Code:
    Private Sub cmdsearch_Click()
    
    Dim strSearch As String
     'Declare the variable strSearch as data type string
     
    Dim strText As String
     'Declare the variable strText as data type string
     
    strText = Me.txtSearch.Value
     'The value from the text box txtSearch is assigned th
     'the varuable strSearch
     
     strSearch = "SELECT *FROM tblSupplier where ((SupplierID Like ""*" & strText "*"")Or _
     (Company Like ""*" & strText "*"") or (FirstName Like ""*" & strText "*"")Or _
     (LastName Like ""*" & strText "*"") or (BusinessPhoneLike ""*" & strText "*"") Or _
     (Address Like ""*" & strText "*"")or (City Like ""*" & strText "*"")"
     
     
    End Sub
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1290

    #2
    Pranish01,
    If you want help you're going to have to invest enough time into your post to tell us what you are trying to do and what the problem is. "It does not work" is not a clear description of what the problem is.

    Jim

    Comment

    • twinnyfo
      Recognized Expert Moderator Specialist
      • Nov 2011
      • 3655

      #3
      Pranish01,

      A brief review of your strSearch and there might be a few minor edits:

      Code:
      strSearch = "SELECT * FROM tblSupplier " & _
          "WHERE SupplierID Like '*" & strText & "*' " & _
          "OR Company Like '*" & strText & "*' " & _
          "OR FirstName Like "'*" & strText & "*' " & _
          "OR LastName Like "'*" & strText & "*' " & _
          "OR BusinessPhoneLike "'*" & strText & "*' " & _
          "OR Address Like "'*" & strText & "*' " & _
          "OR City Like "'*" & strText "*'"
      It appears you were using double quotes instead of single quotes and you were missing the ampersand (&) after your string variable.

      This should get you headed in the right direction.

      Comment

      Working...