Solved

Like Filter and Apostrophes

Posted on 2011-02-18
4
588 Views
Last Modified: 2012-06-27
I have combo box VendorName_Lookup in which a user can type all or part of a Vendor Name which defines a filter on the form to filter for those records where that value is in either of two fields [Vendor] or [DBA].  The problem I run into is when there is an apostrophe in the vendor name (e.g. Sam's).
See code below.
Please help.
Jeff



 
Private Sub VendorName_Lookup_AfterUpdate()

Dim FilterCriteria As String
Dim strsql As String
strsql = "'*" & Me!VendorName_Lookup & "*'"
FilterCriteria = "[Vendor] Like " & strsql & " or [DBA] Like " & strsql
Me.Vendor_sf_Index.Form.Filter = FilterCriteria
Me.Vendor_sf_Index.Form.FilterOn = True

DoCmd.SearchForRecord , "", acFirst, "[Vendor] = " & "'" & Screen.ActiveControl & "'"
End Sub

Open in new window

0
Comment
Question by:wellesleydpw
4 Comments
 
LVL 28

Accepted Solution

by:
omgang earned 400 total points
ID: 34927269
strsql = Chr(34) & "*" & Me!VendorName_Lookup & "*" & Chr(34)

Try that OM Gang
0
 
LVL 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 100 total points
ID: 34927504
or try:

strsql = "'*" & Replace(Me!VendorName_Lookup, "'", "''") & "*'"

This will replace single instances of an apostrophe (') with doublets ('').


0
 
LVL 75
ID: 34927722
Contrary to popular belief ... single quotes are problematic in Access when used in criteria for exactly the issue shown here.

mx
0
 

Author Closing Comment

by:wellesleydpw
ID: 34927812
both solution work well.  I gave the majority of the points to omgang that solution was posted first.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

762 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

22 Experts available now in Live!

Get 1:1 Help Now