Search (Like)

G

Guest

I have a search Form using the following code:
___________________________________
Private Sub SearchClick_Click()
Dim strSql As String

strSql = "select * from items where Description Like '" &
Me.SearchText.Value & "*'"

Me.sbfrmItemsSearch.Form.RecordSource = strSql
Me.sbfrmItemsSearch.Requery

End Sub
___________________________________

It works, however not exactly how I need it to.

The 'Description' column that it is comparing to the user search criteria
(Me.SearchText.Value) is more like a sentence describing an item name (i.e.
"Software Transmittal for I&P: Build Structure 12.05").

With the current search 'Like', it will compare the 'Me.SearchText.Value' to
the first terms in the 'Description' column (i.e. 'Software').
However, let's say a user were to enter "Build Structure" for the search
criteria. This search code would fail to return anything that didn't start
with "Build Structure", even though the 'Description' column of the item does
contain "Build Structure" within the text "Software Transmittal for I&P:
Build Structure 12.05".

Anotherwords, the search above does a "Starts with..." search instead of a
"Contains..." search.
Is there a way to alter it to make it a "Contains..." search?


Thanks for your help in advance.
 
V

Vimal Ori

Did you try to put a * in after Like '

strSql = "select * from items where Description Like '*" &
Me.SearchText.Value & "*'"
 
G

Guest

sweet, that worked. thank you!

Vimal Ori said:
Did you try to put a * in after Like '

strSql = "select * from items where Description Like '*" &
Me.SearchText.Value & "*'"
 
G

Guest

strSql = "select * from items where Description Like '*" &
Me.SearchText.Value & "*'"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help with VBScript/Access database 0
Continuous form search problem 5
search coding 2
Referencing Forms 5
Populating a list box (Part2) 3
Filter Command Button 2
Custom Search String 2
SQL problem 9

Top