Wildcard search with more specific results needed

G

Guest

Hi,
I have a form that displays the Companies that I deal with. I use a combo
box and an unbound text box as my search tools to filter the data related to
the Companies. My problem is that when I enter the search criteria for Labor
Type (there are three choices = Union, Non-Union, n/a) as Union, for example,
I get all of the companies that are Union and Non-Union (not just the Union
records that I am looking for). How do I change my code to accomplish this?
I copied the code I used in my text box below.
Thanks in advance.
Jim

Private Sub txtSearch_AfterUpdate()
On Error Resume Next

Dim strSQL As String

Select Case Me.cboFindBy

Case "Show All Subs"
strWhere = strWhereCurrent

Case "Company"
strWhere = "WHERE [Company] Like '*" & Me.txtSearch & "*'"

Case "Contact #1"
strWhere = "WHERE [Contact #1] Like '*" & Me.txtSearch & "*'"

Case "Work Type"
strWhere = "WHERE [Work Type] Like '*" & Me.txtSearch & "*'"

Case "Labor Type"
strWhere = "WHERE [Labor Type] Like '*" & Me.txtSearch & "*'"

Case Else
Beep
MsgBox "The selected Find By option is not programmed."
Exit Sub

End Select

'strSelect is set in Form_Load event
strSQL = strSelect & strWhere

'MsgBox strSQL

Me.LstJobNo.RowSource = strSQL

End Sub
 
A

Allen Browne

Remove the leading wildcard, i.e.:
strWhere = "WHERE [Labor Type] Like '" & Me.txtSearch & "*'"

If you like the interface with the combo and text box, this link lets you
add it to any form with just a single line of code:
Find as you type - Filter forms with each keystroke
at:
http://allenbrowne.com/AppFindAsUType.html
 

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