Search Box..

abledog

Registered User.
Local time
Today, 04:23
Joined
Nov 11, 2008
Messages
15
Hello:

I have a search box in my access form, with this code behind it (not the cleanest code, I copied it from somewhere...suggestions for improvement are welcome):

Private Sub txtFindShopOrder_AfterUpdate()
Dim strFilter As String, strOldFilter As String
strOldFilter = Me.Filter
'txtFindAccountCode - Text
If Me!txtFindShopOrder > "" Then _
strFilter = strFilter & _
" AND ([Shop Order] Like '" & _
Me!txtFindShopOrder & "*')"
If strFilter > "" Then strFilter = Mid(strFilter, 6)
If strFilter <> strOldFilter Then
Me.Filter = strFilter
Me.FilterOn = (strFilter > "")
End If
Me!txtFindShopOrder.Value = Null
End Sub

Now, I want this code to be able to search any part of the string. For example, lets say there is a record in the table "15W1234"...the search box will return an empty value if I searched for "1234", it will only display the needed records when I type the search criteria from the beginning, i.e. "15W1"....What do I need to add/change to code to make this work..

Thanks for your help....!
 
You need the wildcard at the beginning of the test string as well as the end.
 
Code:
Private Sub txtFindShopOrder_AfterUpdate()
Dim strFilter As String, strOldFilter As String
strOldFilter = Me.Filter
If Me!txtFindShopOrder > "" Then _
strFilter = strFilter & " AND ([Shop Order] [COLOR=Red]Like '*" & Me!txtFindShopOrder & "*')"[/COLOR]
If strFilter > "" Then strFilter = Mid(strFilter, 6)
If strFilter <> strOldFilter Then
Me.Filter = strFilter
Me.FilterOn = (strFilter > "")
End If
Me!txtFindShopOrder.Value = Null
End Sub
 
Thanks a lot....works....don't know how I missed that..:).....Thanks.
 

Users who are viewing this thread

Back
Top Bottom