Search data

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
 
J

Joe Fallon

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
 

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

Top