Here is the code I use. Paste this into a general module and pass your field to it for modification before you put it into your sql string.
useage could look like this...
dim lastName as string
lastName = SpecialCharChk(Your Last Name Field)
mySql = "Select * From myTable Where myTable.LastName like '" & lastName & "'"
----------------------------------------------------------
Public Function SpecialCharChk(strToChk As Variant) As String
Dim strNew As String
Dim strTemp As String
Dim iPos As Integer
Dim iLen As Integer
Dim bDone As Boolean
Dim bCharFound As Boolean
If Not (IsNull(strToChk)) Then
strTemp = strToChk
iLen = Len(strToChk)
Do Until bDone
iPos = InStr(strTemp, "'"
If iPos > 0 Then
bCharFound = True
'double up the special char
strNew = strNew & Left(strTemp, iPos) & "'"
'dont retrive remaining string if ipos = last char
If iLen <> iPos Then
strTemp = Mid(strTemp, iPos + 1)
Else
strTemp = ""
End If
Else
bDone = True
End If
Loop
If bCharFound Then
If Len(strTemp) > 0 Then
strNew = strNew & strTemp
End If
SpecialCharChk = strNew
Else
SpecialCharChk = strToChk
End If
Else
SpecialCharChk = ""
End If
End Function
--------------------------------------------------------- [sig]<p>John A. Gilman<br><a href=mailto:gms@uslink.net>gms@uslink.net</a><br>[/sig]
"SELECT * FROM people WHERE NAME=" & Chr$(34) & "o'donnell" & Chr$(34) & ";"
[sig]<p>Keith C Taylor<br><a href=mailto:TekTips@kctaylor.co.uk>TekTips@kctaylor.co.uk</a><br><a href=
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.