Solved

Filtering Access Recordset when Data Contains both Apostrophe and Quotes?

Posted on 2011-09-28
4
484 Views
Last Modified: 2012-05-12
Hello Experts

I have a table with a text field that has data imported into from an outside source (XLS spreadsheet). I then have a function that loops through this table and searches for occurences of certain text strings. The problem I am having is that sometimes the text strings being searched have quotes in them:
i.e. - 17" rope cord

and sometimes the text strings have single quotes in them
i.e. I's rope cord's

I previously had this code:
 
'Me.strVDestColumn is the column name being searched
'rsProducts(strVSourceColumn) is the text string the recordset is looking for
strCriteria = "[" & Me.strVDestColumn & "] = '" & rsProducts(strVSourceColumn) & "'"
                        
                        'Filtering main product recordset for potential matching data
                        prsMainProducts.FindFirst strCriteria

Open in new window


This code works fine with the double quotes, but fails on single quotes.

How do I universally filter/search for text strings that may have single quotes, may have double quotes, or may have neither?

Thank you!
0
Comment
Question by:w00tw00t111
  • 2
  • 2
4 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility

try this


strCriteria = "[" & Me.strVDestColumn & "] =" & chr(34) & rsProducts(strVSourceColumn) & chr(34)
0
 

Author Comment

by:w00tw00t111
Comment Utility
Capirocorn,

Thank you for your reply. That was my original criteria string and it works fine when there is a single quote in the string, but fails when there is a double quote in the string, such as 17" Rope Cord because the resulting criteria is:

[ItemName]= "17"RopeCord"
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
Comment Utility
try this

strCriteria = "[" & Me.strVDestColumn & "] =" & chr(34) & Replace(rsProducts(strVSourceColumn),chr(34),chr(34) & chr(34)) & chr(34)
0
 

Author Comment

by:w00tw00t111
Comment Utility
Phew! That did it Capricorn! Thank you so much! (Spent several hours on that today with no luck -_-) Thank you!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
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…
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…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

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

10 Experts available now in Live!

Get 1:1 Help Now