The function SqS returns a proper SQL expression for any string - e.g. SqS("O'Connor"

-> 'O''Connor'<br>
<br>
SQL= "Select * from Tbl where Name = " & SqS("O'Connor"

<br>
<br>
Cut and paste this code into VB IDE to read it - " and '' look the same in this font.<br>
<br>
Public Function SqS(Element) As String<br>
SqS = "'" & FindAndReplace(CStr(Element), "'", "''"

& "'"<br>
End Function<br>
<br>
Public Function FindAndReplace(StringToExamine As String, Replace As String, WithThis As String) As _<br>
String<br>
Dim Work As String<br>
Dim Found As String<br>
Dim ix As Integer<br>
Work = StringToExamine<br>
Do While Len(Work) > 0<br>
ix = ThisInThatText(Replace, Work)<br>
If ix = 0 Then<br>
Found = Found & Work<br>
Work = ""<br>
Else<br>
Found = Found & Left$(Work, ix - 1) & WithThis<br>
Work = Mid$(Work, ix + Len(Replace))<br>
End If<br>
Loop<br>
FindAndReplace = Found<br>
End Function<br>
<br>
Public Function ThisInThatText(ThisString As String, InThatString As String, Optional _<br>
StartPositionInThatString = 1) As Long<br>
ThisInThatText = InStr(StartPositionInThatString, InThatString, ThisString, vbTextCompare)<br>
End Function<br>
<br>
<p>Roy Lofquist<br><a href=mailto:roylofquist@msn.com>roylofquist@msn.com</a><br><a href= > </a><br>