Search Form

G

Guest

I have created a search form that I want the user to be able to put in part
of the word and retrieve search results against it. I am able to put the
code in so that whatever the user puts in will retrieve any row with that
text, but I want the search to take the text input and do the wildcard search
after. For example:

Search Field = s - currently search will return any record with an s in the
field, I want it to return any record with an s at the beginning. Here is my
current code:

f Not IsNull(Me.txtTitle) Then
strWhere = strWhere & "([Title] Like ""*" & Me.txtTitle & "*"") AND "
End If
 
G

Guest

In that case remove the wild card form the beginning

Yours
strWhere = strWhere & "([Title] Like ""*" & Me.txtTitle & "*"") AND "

Change to
strWhere = strWhere & "([Title] Like Me.txtTitle & "*"") AND "
 
S

Scott McDaniel

I have created a search form that I want the user to be able to put in part
of the word and retrieve search results against it. I am able to put the
code in so that whatever the user puts in will retrieve any row with that
text, but I want the search to take the text input and do the wildcard search
after. For example:

Search Field = s - currently search will return any record with an s in the
field, I want it to return any record with an s at the beginning. Here is my
current code:

f Not IsNull(Me.txtTitle) Then
strWhere = strWhere & "([Title] Like ""*" & Me.txtTitle & "*"") AND "
End If

You didn't mention how you're doing the search, but if you're using ADO you'll need to use the % as the wildcard
delimiter:

If Not IsNull(Me.txtTitle) Then
strWhere = strWhere & "([Title] Like ""%" & Me.txtTitle & "%"") AND "
End If

Note also that your search will find all records with the value of txtTitle ANYWHERE in the Title column, not just the
beginning. If you want to match only on the beginning, then remove the last %


Scott McDaniel
scott@takemeout_infotrakker.com
www.infotrakker.com
 
G

Guest

Thanks for the quick response, however, when updating the search it does not
seem to work - I get a compile error, stating "Expected: end of statement".
Is there something I'm doing wrong?



Ofer Cohen said:
In that case remove the wild card form the beginning

Yours
strWhere = strWhere & "([Title] Like ""*" & Me.txtTitle & "*"") AND "

Change to
strWhere = strWhere & "([Title] Like Me.txtTitle & "*"") AND "

--
Good Luck
BS"D


mes said:
I have created a search form that I want the user to be able to put in part
of the word and retrieve search results against it. I am able to put the
code in so that whatever the user puts in will retrieve any row with that
text, but I want the search to take the text input and do the wildcard search
after. For example:

Search Field = s - currently search will return any record with an s in the
field, I want it to return any record with an s at the beginning. Here is my
current code:

f Not IsNull(Me.txtTitle) Then
strWhere = strWhere & "([Title] Like ""*" & Me.txtTitle & "*"") AND "
End If
 

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