Wow, that stirred things up a bit didn't it.
To enlarge on my problem. I have two attached tables that
are generated by a db4 database one is a list of names and
the other is a list of addresses. In the names database
there is an ID that points to an address in the addresses
table.
The address ID for a person is a four character code which
(invariably) starts with a double double quote, a
character and then maybe a single quote. e.g ""Z' or "'a"
(all the quotes are in the ID) etc. Only a few of the IDs
have both single and double quotes.
The DB4 database seems to be case sensitive, as an address
ID for a person may be ""z" but when he changes address
the new address will have the ID ""Z". I have sorted the
case bit by using strcompare on the find, but am still
having probs with the quotes. I don't feel inclined to
change the single quotes in either table's ID field to a
double quote (although this may be the only answer).
Any further conversations on this matter will be more than
welcome..
Thanks chaps
Trevor
-----Original Message-----
Roger
Try this in the immediate window
field = "37"" TV" : strcriteria = "[ID] = " & Chr$(34) & (field) &
Chr$(34) : ? strcriteria
When there is an embedded Double Quote in the variable field then the
resulting expression
[ID] = "37" TV"
which is a bad expression.
On The Other Hand
field = "37"" TV": strcriteria = "[ID] = " & Chr$(39) & (field) &
Chr$(39): ? strcriteria
which results in
[ID] = '37" TV'
OR
field = "37"""" TV": strcriteria = "[ID] = " & Chr$(34) & (field) &
Chr$(34): ? strcriteria
which results in
[ID] = "37"" TV"
Will work OK
Now I grant you it is far more likely that you will run into an embedded
Single quote more often than a Double quote, but it only takes one 19"
monitor or 12.2" brake rotor to ruin a perfectly wonderful day with a
support call. The only way to avoid getting that support call is to double
up on the character that you choose to use as the Sql delimiter be it a
single or double quote.
Ron W
Sorry, I missed the bit in the first post about the field having both
apostrophes and quotes. Still, he seemed reluctant to use your code, so I
would suggest the following:
strcriteria = "[ID] = " & Chr$(34) & (field) & Chr$(34)
This will avoid the problem altogether.
On my website, there is a complete discussion of using
embedded quotes
that
I excerpted from an out-of-print book by Ken Getz. It has the best
explanation I have ever seen. You can find it here:
http://www.rogersaccesslibrary.com/knowledge.html
--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org
Roger
You are absolutely correct about replacing the single
Quote with a pair
of
Double Quotes, but all that will do is to make the
problem he has now
with
embedded Single Quotes to embedded Double Quotes. What happens if he
wants
to do something like:
strcriteria ="ID = """ & (field) & """"
where the value in field is '19" monitor' or 'the "Smiths" house'
No matter how you shake it or bake it sometime, somewhere he will get an
error when the conditions are right (or wrong depending on ones point of
view). To have it work ALL of the time he needs to look at a method of
"Escaping" either the single or double quote
depending on what he
decides
to
use as a delimiter.
Ron W
Well, if you don't want to use FixQuotes (which will work with ANY
string
in
your database if you save it in a general module), you can replace the
apostrophe (') with TWO quotes:
strcriteria ="ID = """ & (field) & """"
--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org
Anybody help please.
I am using a linked DB4 table in my Access database. I
need to lookup (using FindFirst etc.) an ID field that may
contain either single quotes, double quotes or both. I am
OK when the string contains double quotes, I use
somethging like
strcriteria ="ID = '" & (field) & "'"
rst.FindFirst strcriteria
But of coure, this fails when field contains a single
quote. Is there any way round this? I vaguely remember
that another delimeter can be used, but can't remember
what it is (but just to screw me up, I bet that character
is also in my search string.
TIA
Trevor
.