By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,717 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,717 IT Pros & Developers. It's quick & easy.

Search code does not work

P: 5
I have break VBA code but it does not work

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdsearch_Click()
  2.  
  3. Dim strSearch As String
  4.  'Declare the variable strSearch as data type string
  5.  
  6. Dim strText As String
  7.  'Declare the variable strText as data type string
  8.  
  9. strText = Me.txtSearch.Value
  10.  'The value from the text box txtSearch is assigned th
  11.  'the varuable strSearch
  12.  
  13.  strSearch = "SELECT *FROM tblSupplier where ((SupplierID Like ""*" & strText "*"")Or _
  14.  (Company Like ""*" & strText "*"") or (FirstName Like ""*" & strText "*"")Or _
  15.  (LastName Like ""*" & strText "*"") or (BusinessPhoneLike ""*" & strText "*"") Or _
  16.  (Address Like ""*" & strText "*"")or (City Like ""*" & strText "*"")"
  17.  
  18.  
  19. End Sub
  20.  
Jun 16 '14 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,240
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
Jun 16 '14 #2

twinnyfo
Expert Mod 2.5K+
P: 3,486
Pranish01,

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

Expand|Select|Wrap|Line Numbers
  1. strSearch = "SELECT * FROM tblSupplier " & _
  2.     "WHERE SupplierID Like '*" & strText & "*' " & _
  3.     "OR Company Like '*" & strText & "*' " & _
  4.     "OR FirstName Like "'*" & strText & "*' " & _
  5.     "OR LastName Like "'*" & strText & "*' " & _
  6.     "OR BusinessPhoneLike "'*" & strText & "*' " & _
  7.     "OR Address Like "'*" & strText & "*' " & _
  8.     "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.
Jun 16 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.