Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a string to accept quotes

Status
Not open for further replies.

zp162002

Programmer
Feb 3, 2003
39
US
I need to create a filter that will accept double quotes inside a string. My current line of code is:

strFilter = "[SpecificMatter] = """ & Me.SpecificMatter & """"

This will accept single quotes but not double quotes. Can anyone help me? Thanks in advance.
 
Try using single quotes as the delimiter in your filter.

strFilter = "[SpecificMatter] = '" & Me.SpecificMatter & "'"
 
Thanks for the quick reply. I tried as you suggested but I get the error message:

Syntax error (missing operator) in query expression 'SpecificMatter = "Test"Test'".

 
Hi zp162002,

I'm afraid you're going to have problems if you want to create a filter with a string which contains BOTH single and double quotes.

To include the string delimiter inside a quoted string, it must be doubled; if your string can contain both you must pick one as the delimiter and make sure all occurrences of it are doubled.

Try something like this ..

[blue]
Code:
strFilter = "[SpecificMatter] = '" & Replace(Me.SpecificMatter,"'","''") & "'"
[/blue]

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Hi Tony. Unfortunately, We still use Access97 here and it doesn't recognize the replace function. I may have to write some additonal code to perform a search for a double quote and to change it to a single quote. Thanks for the help.
 
Why not using Chr(34) ?

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Hi zp162002,

There are several postings of code here to provide Replace functionality in Access 97 - I just did a quick search and this is the first one I found: thread701-792701, check out the post by member Golom

PH,

Using Chr(34) won't help in this case as the problem is with the re-interpretation of the built string when used as a Filter - it doesn't matter how you get it into that string provided that, when it's there, it's doubled up.

Enjoy,
Tony

--------------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top