UtterAccess HomeUtterAccess Wiki

Welcome Guest ( Log In | Register )

Custom Search
Edit Discussion
> QuoteFix    


Synopsis

Resolve single and double quotes within string arguments and parameters. Original name SQLQuote, but posted on UA as QuoteFix for more intuitive reference. I have been posting this code for years, always acknowledging the original author, Stefan Hoffman. Stefan was an Access MVP at one time, but does not appear to be now. He made the function freely available 11 years ago, so I am assuming he is OK with sharing it here. BruceM

CODE
' QuoteFix
' http://www.utteraccess.com/wiki/QuoteFix
' Code courtesy of UtterAccess Wiki
' Licensed under Creative Commons License
' http://creativecommons.org/licenses/by-sa/3.0/
'
' You are free to use this code in any application,
' provided this notice is left unchanged.
'
' rev  date                          brief descripton
' 1.0  2018-11-06                    
'
'---------------------------------------------------------------------------------------
' Author    : Stefan Hoffman, from a newsgroup posting 20-Sep-2007, with minor edits.
' Purpose   : Resolve quotes within string arguments:
'             strWhere = "LastName = " & SQLQuote(Me.LastName)
'---------------------------------------------------------------------------------------

Public Function QuoteFix (ByVal AString As String) As String

 Const Delimiter As String = "'"

 QuoteFix = _
   Delimiter & _
   Replace(AString, Delimiter, Delimiter & Delimiter) & _
   Delimiter

End Function

' To allow for the possibility of the argument being Null, as an _
 alternative to testing the argument before passing it to the _
 function, something like this:

Public Function QuoteFix (ByVal AString As Variant) As Variant

 Const Delimiter As String = "'"

 If Not IsNull(AString) Then
     QuoteFix = _
       Delimiter & _
       Replace(AString, Delimiter, Delimiter & Delimiter) & _
       Delimiter
 End If

End Function

Creative Commons License
QuoteFix by UtterAccess Wiki is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Editing and revision of the content is freely encouraged; for details, see Expected Usage.

Edit Discussion
Custom Search


Thank you for your support!
This page has been accessed 1,428 times.  This page was last modified 15:39, 6 November 2018 by BruceM.   Disclaimers