Search Form

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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 "
 
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
 
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
 
Back
Top