?
Solved

VBA Syntax for wildcard filter

Posted on 2011-02-15
5
Medium Priority
?
2,337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 120

Expert Comment

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

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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 …

764 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