Solved

VBA Syntax for wildcard filter

Posted on 2011-02-15
5
2,117 Views
Last Modified: 2012-05-11
I use the following code under a button to filter a form based on the Business Name field:

Me.Filter = "[Business Name]='" & Me.Find & "'"
Me.FilterOn = True
Me.Requery

This works well for a one word business name such as "Acme"

I would like to change the filter to allow the use of the * wild card so I can find "Acme Inc." "Acme Corp" or "The Acme Company":

How do I change this syntax to filter by business name with the star wildcard before and after

Thank you in advance for your help.

Bob
0
Comment
Question by:Rwardlow
  • 2
  • 2
5 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 34897737
Me.Filter = "[Business Name] Like '" & Me.Find & "*'"
Me.FilterOn = True
Me.Requery
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 34897747
Me.Filter = "[Business Name] Like '*" & Me.Find & "*'"
Me.FilterOn = True
0
 
LVL 1

Author Comment

by:Rwardlow
ID: 34897939
Perfect. Thank you so much.
0
 
LVL 1

Author Closing Comment

by:Rwardlow
ID: 34897949
Great, thanks
0
 
LVL 61

Expert Comment

by:mbizup
ID: 34897973
I'd recommend using the LIKE operator without embedding the wildcards in the code as follows:

Me.Filter = "[Business Name] Like '" & Me.Find & "'"

This allows the user to specify any wildcard in the search text:

*ACME*  (* for multiple characters)
?ACME    (? for a single character)

or return exact search results by specifying no wildcards:

ACME   (will return exact name)
0

Featured Post

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now