Solved

VBA Syntax for wildcard filter

Posted on 2011-02-15
5
2,224 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 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

756 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