Search data

  • Thread starter Thread starter kietvothanh
  • Start date Start date
K

kietvothanh

Help me!

I would like to write code which will search records
containing a string that I input in a form.

Ex: when inserting "kiet", the program will search in a
table and select all records containing "kiet" (kietvo,
vothanhkiet, kietvt, etc.)

Thanks a lot
 
You have to write SQL for that.
Assuming you have a form with a text box named txt1 and a table with 3
fields to search then try
something like:

Dim strSQL As String
Dim strWhere As String
strWhere = "(Field1 Like '*" & Me![txt1] & "*' OR " & "Field2 Like '*" &
Me![txt1] & "*' OR " & "Field3 Like '*" & Me![txt1] & "*')"

strSQL = "SELECT * "
strSQL = strSQL & "FROM MyTable "
strSQL = strSQL & "WHERE " & strWhere
 
Back
Top