Solved

Filtering Access Recordset when Data Contains both Apostrophe and Quotes?

Posted on 2011-09-28
4
490 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 500 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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

756 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