dbTalk Databases Forums  

FindFirst Tripping Over Embedded Apostrophe

comp.databases.ms-access comp.databases.ms-access


Discuss FindFirst Tripping Over Embedded Apostrophe in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
(PeteCresswell)
 
Posts: n/a

Default FindFirst Tripping Over Embedded Apostrophe - 10-10-2011 , 01:21 PM






The problem code:
------------------------------------------------------------------
targetRS.FindFirst "DocumentName_App='" & !DocumentName_App & "'"
------------------------------------------------------------------

throws RunTime Error 3077 Syntax Error (Missing operator in
expression)


The problem expression resolves thusly:
------------------------------------------------------------------
?"DocumentName_App='" & !DocumentName_App & "'"
DocumentName_App='Deal000579.Hewett's+Island+CLO+V +Note+Valuation+Report+08.30.2011.pdf'
------------------------------------------------------------------

Clearly it's the apostrophe in "Hewett's" and I could wimp out by
just stripping out embedded apostrophes in any file names I come
across during the process - so they never get to FindFirst.

But I'm guessing there's a "right" way to deal with this.

Replacing the single apostrophe with two apostrophes makes the
error go away. As in Whatever = Replace(Whatever, "'", "''")

But I don't know what I'm getting in to there. Is FindFirst
then looking for just ...Hewlet's..., or is it now looking for
....Hewlet''s...?

Can anybody elucidate?
--
PeteCresswell

Reply With Quote
  #2  
Old   
(PeteCresswell)
 
Posts: n/a

Default Re: FindFirst Tripping Over Embedded Apostrophe - 10-10-2011 , 01:29 PM






Per (PeteCresswell):
Quote:
But I don't know what I'm getting in to there. Is FindFirst
then looking for just ...Hewlet's..., or is it now looking for
...Hewlet''s...?
OK, dumb question.....

The answer, FWIW, is that FindFirst is now looking for the
correct value ...Hewlet's...

The double apostrophe gets converted on-the-fly to a single
apostrophe as it is fed to FindFirst.
--
PeteCresswell

Reply With Quote
  #3  
Old   
Duncan
 
Posts: n/a

Default Re: FindFirst Tripping Over Embedded Apostrophe - 10-11-2011 , 03:18 PM



On Oct 11, 4:29*am, "(PeteCresswell)" <x...@y.Invalid> wrote:
Quote:
Per (PeteCresswell):



But I don't know what I'm getting in to there. * Is FindFirst
then looking for just ...Hewlet's..., or is it now looking for
...Hewlet''s...?

OK, dumb question.....

The answer, FWIW, is that FindFirst is now looking for the
correct value ...Hewlet's...

The double apostrophe gets converted on-the-fly to a single
apostrophe as it is fed to FindFirst.
--
PeteCresswell
Option to try
I had a problem with apostrophes for a name lookup search function on
a form.
Problem code - DoCmd.ApplyFilter , "Name = '" & strFilter & "'"
Good code - DoCmd.ApplyFilter , "Name = " & Chr(34) & strFilter &
Chr(34)
The advice given to me was to replace the apostrophe with Chr(43)
You then can do not need to worry about the "" characters
This worked well for me
Names with apostrophes were my problem.
Cheers
Duncan

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.