Wildcard search funtionality

paulcraigdainty

Registered User.
Local time
Today, 04:18
Joined
Sep 25, 2004
Messages
74
I am working on a form that will be used to search records in a table. I have created the query shown below:

SELECT tblSTC.STC, *
FROM tblSTC
WHERE (((tblSTC.STC) Like forms!frmsearch!txtsearch));

I want my user to be able to enter search criteria and allow the use of a wildcard. When i run the query no data is found??

Can anyone help, thanks.
 
Paul,

VBA:

Code:
sql = "SELECT * " & _
      "FROM tblSTC " & _
      "WHERE STC Like '*" & Forms!frmSearch!txtsearch & "*'"

In the Query grid, your criteria should be:

Like "*" & Forms!frmSearch!txtsearch & "*"

Wayne
 
Thanks for the response. I am understanding the logic behind the code and the critieria entry, however, do i use both the code and the criteria in the query grid? What I want to happen is the following: I want the code to execute on an exit event of a text box, so I want the user to be able to use the wildcard in the text box. I want the results of the query to be displayed in a list box so that the user can pick the relevant one.
 
See the attached database, it has the search fields with criteria set in the query used to populate the datasheet. You can enter * on the field to see all the records.
 

Attachments

Users who are viewing this thread

Back
Top Bottom