Solved

VBA Syntax for wildcard filter

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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.

919 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

21 Experts available now in Live!

Get 1:1 Help Now