Generic character escape function for SQL

kwatai

Registered User.
Local time
Today, 10:33
Joined
Jul 19, 2001
Messages
11
Hello,
The subject says it all but I'm looking for some way to escape all special characters for SQL. I'm taking direct input from the user, and composing SQL statements but special characters are screwing up the parsing and craps out. I'm sure its come up before, but I can't find the code for it.

Any premade function or custom functions out there?
thx
Kenta
 
Here is a UDF that removes everything but alphnumerics:

Public Function strclean(strDirty As String) As String
Dim intCode As Integer
Dim intNameLen As Integer
Dim intCheck As Integer
strclean = ""
intNameLen = Len(strDirty)
intCode = 1
Do Until intCode = intNameLen + 1
intCheck = Asc(Mid(strDirty, intCode, 1))
If intCheck < 48 Or intCheck > 122 Then
Else
If (intCheck > 57 And intCheck < 65) Or (intCheck > 90 And intCheck < 97) Then
Else
strclean = strclean & Chr(intCheck)
End If
End If
intCode = intCode + 1
Loop
End Function
 

Users who are viewing this thread

Back
Top Bottom