I have set up a form that filters based on the selection in a dropdown box. If the filter is [Subject] = 'subject', that works properly. However, if the filter sql string is [Subject]='isn't subject', that generates an error and the form will not filter. I tried the following without success:
Any advice on this is much appreciated.
Code:
Public Function CheckForQuotes(someText) As Variant
If IsNull(someText) Then
CheckForQuotes = Space(1)
Exit Function
End If
Dim chrSingleQuote As String: chrSingleQuote = "'"
Dim chrDoubleQuote As String: chrDoubleQuote = """"
Dim start%, length%, remainder%, x%
Dim strPart1, strRemainder As String
Dim strBase, strNew As Variant
start% = 1
strBase = someText
strNew = ""
Do
x% = InStr(start%, strBase, chrSingleQuote, vbTextCompare)
If x% <> 0 Then
strPart1 = Mid(strBase, start%, x% - start%)
strNew = strNew & strPart1
strNew = strNew & "''"
start% = x% + 1
End If
Loop Until x% = 0
strNew = strNew & Mid(strBase, start%)
CheckForQuotes = strNew
End Function
Comment