Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search only filters exact matches.....

Status
Not open for further replies.

inzzane

Technical User
Sep 23, 2004
4
0
0
US
Maybe someone here can help me out. A simple search, but somethings wrong.
This search works, but only for exact entries. I cant seem to get it to work for partial searches.

Simply, when I use this here, I get a working filter. But I need to know the exact spelling of the Company name. How do I make it to where I can type in "ompa" instead of "Company" to get a list of results?

*****************************
Private Sub Command58_Click()
On Error GoTo Err_Command58_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmCompanyInfo"

stLinkCriteria = "[strCity]=" & "'" & Me![Text56] & "'"
DoCmd.OpenForm stDocName, , , stLinkCriteria

Exit_Command58_Click:
Exit Sub
 
I will assume that Me![Text56] is the text box with the string search criteria.

For partial search strings you need to use the "like" operator, the wildcard character, and a combination of single and double quotes.

The stLinkCriteria would be as follows.

stLinkCriteria = "[strCity] like '*" & Me![Text56] & "*'"

When the stLinkCriteria is parsed it will be: [strCity] like '*ompa*'

It doesn't matter if the partial search string is the first few letters, letters from the middle, or the end characters of the city.
 
Sweet, it works now...thanks!
The "Like" operator wasnt working for me when I tried....
It appears my error codes were caused by removing the ' and replacing them with *, instead of placing the * next to the '.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top