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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Wildcard Searches in VBA

Status
Not open for further replies.

Muzzery

Programmer
Jan 11, 2002
72
GB
Does anyone know how to do this? Search through a field in Access using the Wildcard (* if unsure) option?

I need the code to put on a button via VBA to open up another form with the results on. At the moment, i'm using a simple filter, so the user only see's exact results, is there a way to search for fo* for example and bring back anything begining fo?

Cheers

Muzz :)
 
Hi Muzz!

What I usually do is put a frame control on the search form and add four buttons:

1. Exact Match
2. Starting With
3. Ending With
4. Anywhere in Field

The user selects the type of search and uses a text box to input the search string. In the button's click event I use the following code:

Dim strCriteria

Select Case FrameControl.Value
Case 1
strCriteria = "YourField = '" & Me!TextBox & "'"
Case 2
strCriteria = "YourField Like '" & Me!TextBox & "*'"
Case 3
strCriteria = "YourField Like '*" & Me!TextBox & "'"
Case 4
strCriteria = "YourField Like '*" & Me!TextBox & "*'"
End Select

DoCmd.OpenForm "YourForm", , , strCriteria

hth
Jeff Bridgham
bridgham@purdue.edu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top