
Nightmares with the apostrophe!!!!!!!!!!!!
I find it easiest to use a function, so that I can do this:
strSQL = "SELECT * FROM tTableX WHERE ([tTableX].[Surname] = " & _
mStrQuote("O'Connor") & ");"
The underscore character (_) at the end of the first line is so Access knows
the line
continues.
----------------------------------------------------------------------
Public Function mStrQuote(ByVal varVal As Variant) As String
On Error Resume Next
mStrQuote = vbNullString
varVal = Trim(varVal)
If Not mChkIsNothing(varVal) Then
mStrQuote = varVal
If (varVal Like Chr$(34) & "*" & Chr$(34)) Then Exit Function
mStrQuote = Chr$(34) & varVal & Chr$(34)
End If
End Function 'mStrQuote
----------------------------------------------------------------------
Public Function mChkIsNothing(ByVal varVal As Variant) As Boolean
On Error Resume Next
mChkIsNothing = True
varVal = Trim(varVal)
If IsNull(varVal) Or IsEmpty(varVal) Then Exit Function
If Len(varVal) < 1 Then Exit Function
mChkIsNothing = False
End Function 'mChkIsNothing
----------------------------------------------------------------------
Quote:
> Everytime any of the variables contains an apostrophe, I get the Syntax
> Error message...
> Has anybody found any other way to deal with this?