Help with search code

  • Thread starter Afrosheen via AccessMonster.com
  • Start date
A

Afrosheen via AccessMonster.com

The code below works great. I just want to make it work better.
I want the ability to do the search with a Wild Card * So when I put in Dom
it will give me all the names with the letters Dom and beyond like Dominic
and so on. Is there a way of doing this?

10 If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
20 MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!
"
30 Me![txtSearch].SetFocus
40 Exit Sub
50 End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch and evaluates
this against values in lName
60 'strwhere = txtSearch

strWhere = "[lname] = '" & Me!txtSearch & "'"
Filter = strWhere
FilterOn = True

Thanks for your help.
 
M

Marshall Barton

Afrosheen said:
The code below works great. I just want to make it work better.
I want the ability to do the search with a Wild Card * So when I put in Dom
it will give me all the names with the letters Dom and beyond like Dominic
and so on. Is there a way of doing this?

10 If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
20 MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!
"
30 Me![txtSearch].SetFocus
40 Exit Sub
50 End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch and evaluates
this against values in lName
60 'strwhere = txtSearch

strWhere = "[lname] = '" & Me!txtSearch & "'"
Filter = strWhere
FilterOn = True

If you always want to search fo a partial match:

strWhere = "[lname] Like '" & Me!txtSearch & "*' "

If you want user to enter Dom* when they want a partial
match or enter Dom when they want an exact match, then use:

strWhere = "[lname] Like '" & Me!txtSearch & "* "
 
J

John Spencer

Marshall meant to say

If you want user to enter Dom* when they want a partial
match or enter Dom when they want an exact match, then use:

strWhere = "[lname] Like '" & Me!txtSearch & "' "

Note the replacement of the * with a '

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County

Marshall said:
Afrosheen said:
The code below works great. I just want to make it work better.
I want the ability to do the search with a Wild Card * So when I put in Dom
it will give me all the names with the letters Dom and beyond like Dominic
and so on. Is there a way of doing this?

10 If IsNull(Me![txtSearch]) Or (Me![txtSearch]) = "" Then
20 MsgBox "Please enter a value!", vbOKOnly, "Invalid Search Criterion!
"
30 Me![txtSearch].SetFocus
40 Exit Sub
50 End If
'---------------------------------------------------------------
'Performs the search using value entered into txtSearch and evaluates
this against values in lName
60 'strwhere = txtSearch

strWhere = "[lname] = '" & Me!txtSearch & "'"
Filter = strWhere
FilterOn = True

If you always want to search fo a partial match:

strWhere = "[lname] Like '" & Me!txtSearch & "*' "

If you want user to enter Dom* when they want a partial
match or enter Dom when they want an exact match, then use:

strWhere = "[lname] Like '" & Me!txtSearch & "* "
 
A

Afrosheen via AccessMonster.com

Thanks fellas. It works great. I appreciate the help, advice, and little
tricks I've learned and probably forgot.

Thanks again.

John said:
Marshall meant to say

If you want user to enter Dom* when they want a partial
match or enter Dom when they want an exact match, then use:

strWhere = "[lname] Like '" & Me!txtSearch & "' "

Note the replacement of the * with a '

John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
[quoted text clipped - 24 lines]
strWhere = "[lname] Like '" & Me!txtSearch & "* "
 
M

Marshall Barton

John said:
Marshall meant to say
If you want user to enter Dom* when they want a partial
match or enter Dom when they want an exact match, then use:

strWhere = "[lname] Like '" & Me!txtSearch & "' "

Note the replacement of the * with a '


I guess I need to use a larger font :-(

Thanks for catching that John.
 

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

Similar Threads

Need help with this code 0
Detail in form goes blank 5
Search form help 3
Search Button 2
Working with Filters 0
Optional Search 0
Need help with programming again 2
Seaching using text box 6

Top