Solved

Like Filter and Apostrophes

Posted on 2011-02-18
4
600 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

863 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

18 Experts available now in Live!

Get 1:1 Help Now