Mouse
Mouse

Reputation: 21

Performing a query search to match characters instead of exact words.

I have a form that contains a command button, six unbound text boxes, and a query subform. The user enters data in the unbound text boxes to search for. When they press the search command button the query will search for the data entered into the text boxes. I have no problem with this working with my current code. However, if the user does not enter the information exactly as it is in the main table then a message box saying “No records found” is displayed. I know this may be a very simple fix but I would like for when the user enters data (example: cable) the query should display all records that contain the word or characters (example: rj-45 cable).

 If DCount("*", "Admin Customer Owned Parts Query") = 0 Then
    MsgBox "No Records Found"
    Else
        Me.Admin_Customer_Owned_Parts_Query_Subform.Requery
End If

Upvotes: 0

Views: 114

Answers (1)

jhTuppeny
jhTuppeny

Reputation: 970

You need to set your query to use the LIKE operator and then enclose your search terms in *'s. So if you wanted to find the word cable anywhere in the field you would put;

WHERE Fieldname LIKE '*cable*'

in your query's SQL statement.

Upvotes: 1

Related Questions