Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 552
  • Last Modified:

Filtering Access Recordset when Data Contains both Apostrophe and Quotes?

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
w00tw00t111
Asked:
w00tw00t111
  • 2
  • 2
1 Solution
 
Rey Obrero (Capricorn1)Commented:

try this


strCriteria = "[" & Me.strVDestColumn & "] =" & chr(34) & rsProducts(strVSourceColumn) & chr(34)
0
 
w00tw00t111Author Commented:
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
 
Rey Obrero (Capricorn1)Commented:
try this

strCriteria = "[" & Me.strVDestColumn & "] =" & chr(34) & Replace(rsProducts(strVSourceColumn),chr(34),chr(34) & chr(34)) & chr(34)
0
 
w00tw00t111Author Commented:
Phew! That did it Capricorn! Thank you so much! (Spent several hours on that today with no luck -_-) Thank you!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now