here is a function I wrote a couple years back.
(probably can be simplified/improved but works fine)
I use the javascript part of it just for the purpose you are talking about
Function FixStr(StrToFix,FixHow)
' This function prepares a string for saving in the database
' And also can prepare a string for editing in a text box
' The reason we need to do this is to stop users from entering HTML or
Javascript
' And also to make sure line breaks get converted to <br> tags
If Not IsNull(StrToFix) and StrToFix <> "" Then
If FixHow = "PrepareForSave" then
StrToFix = replace(StrToFix,"<","<")
StrToFix = replace(StrToFix,">",">")
StrToFix = Replace(StrToFix,vbCr,"<br>")
ElseIf FixHow = "PrepareForTextBox" then
StrToFix = replace(StrToFix,"<","<")
StrToFix = replace(StrToFix,">",">")
StrToFix = Replace(StrToFix,"<br>",vbCr)
ElseIf FixHow = "PrepareForJavaScript" then
StrToFix = replace(StrToFix,"'","\'")
StrToFix = replace(StrToFix,"""","\'\'")
StrToFix = Replace(StrToFix,vbCrLf,"<br>")
StrToFix = Replace(StrToFix,vbLf,"<br>")
StrToFix = Replace(StrToFix,vbNewLine,"<br>")
End If
End If
FixStr = StrToFix
End function
and you use it like this
FixStr(YourVariable,"PrepareForJavaScript")
I got the idea from an article at
www.powerasp.com
"Les Juby" <> wrote in message
news:...
>A client needs a routine to alert him as to which memo records in an
> Access-2000 database have had double apostrophes inserted in the text.
> These are stopping a Java mouseover from executing.
>
> Normally, while cycling through the recordset, I would use the InStr
> function to test for a positive result indicating and embedded text.
>
> ie. If InStr(rstemp("Keywords"),"searched") > 0 Then
>
> would give a true for all <keywords> fields that contained the text
> < searched >
>
> But what do you do if you're looking for a double apostrophe itself.?
>
> To specify the string you are searching for you can't use a single
> apostrophe to deliniate the string, such as ' " ' and of course
> using " " " won't work either.
>
> Is there a character expression maybe that one could use instead.?
>
> Or can someone perhaps suggest shattering my paradigm by using
> something other than an If test on a function. Or maybe a different
> function.?
>
> thanks ( in anticipation )
>
> . les .
>