Difficulty with search string

J

JonnyB

Hi

Having a problem with a search string routine that checks to see whether a
name entered is a diplicate. I build the strings as:

stLinkCriteria = "[OrgName]=" & "'" & strOrgName & "'"

which works fine as long as there is no apostrophe in the name. If I input a
name such as Women's Network, I get a Run-time error 3075: missing operator.
I know that I need to alter the way in which quotes appear, but I am
struggling. Can anyone help me please.

Thanks

JonnyB
 
S

Stefan Hoffmann

hi Johnny,
which works fine as long as there is no apostrophe in the name. If I input a
name such as Women's Network, I get a Run-time error 3075: missing operator.
I know that I need to alter the way in which quotes appear, but I am
struggling. Can anyone help me please.
You need to escape the used string delimiter by doubling it, e.g.

Public Function SQLQuote(AString As String, _
Optional ADelimiter As String = "'" _
) As String

SQLQuote = ADelimiter & _
Replace(AString, ADelimiter, ADelimiter & ADelimiter) & _
ADelimiter

End Function

and

stLinkCriteria = "[OrgName]=" & SQLQuote(strOrgName)



mfG
--> stefan <--
 
J

JonnyB

Hi Stefan

Great, both yours and Douglas' approach worked. I have gone for your
universal approach since I use such strings in other forms.

Thanks for your help.

Jonny

Stefan Hoffmann said:
hi Johnny,
which works fine as long as there is no apostrophe in the name. If I input a
name such as Women's Network, I get a Run-time error 3075: missing operator.
I know that I need to alter the way in which quotes appear, but I am
struggling. Can anyone help me please.
You need to escape the used string delimiter by doubling it, e.g.

Public Function SQLQuote(AString As String, _
Optional ADelimiter As String = "'" _
) As String

SQLQuote = ADelimiter & _
Replace(AString, ADelimiter, ADelimiter & ADelimiter) & _
ADelimiter

End Function

and

stLinkCriteria = "[OrgName]=" & SQLQuote(strOrgName)



mfG
--> stefan <--
 
J

JonnyB

Hi Doug

Thanks for your help, your sugestion worked. Your May 2004 article also
helped me to resolve this issue once and for all!

Thank you

Jonny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top