Solved

Like Filter and Apostrophes

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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 …
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …

679 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