?
Solved

Filtering Access Recordset when Data Contains both Apostrophe and Quotes?

Posted on 2011-09-28
4
Medium Priority
?
536 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36719818

try this


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

Author Comment

by:w00tw00t111
ID: 36719834
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 36719858
try this

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

Author Comment

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

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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.

719 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