apostrophes in names

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • StephanieCat
    New Member
    • Mar 2007
    • 5

    apostrophes in names



    I found solution in the above thread but it did not work in my case. Is there any other way of solving this apostrophe problem?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by StephanieCat
    http://www.thescripts. com/forum/thread598894.ht ml

    I found solution in the above thread but it did not work in my case. Is there any other way of solving this apostrophe problem?
    This Function, straight from the Access 2002 Developers Handbook, will handle all problems with apostrophes in names. Simply pass the String to the Function, and it will make it usable in Criteria specification situations. If your Delimiter is not an apostrophe, specify otherwise in the 2nd Argument:
    Code:
    Public Function adhHandleQuotes(ByVal varValue As Variant, Optional Delimiter As String = "'") As Variant
        ' Replace all instances of a string delimiter with TWO instances,
        ' thereby handling the darned quote issue once and for all. Also,
        ' surround the string with the delimiter, as well.
        
        ' Returns Null if the String was Null, otherwise
        ' returns the String with all instances of strDelimiter
        ' replaced with two of each.
            
        adhHandleQuotes = _
         strDelimiter & _
         Replace(varValue, strDelimiter, strDelimiter & strDelimiter) & _
         strDelimiter
    End Function
    ' adhHandleQuotes ("This 'is' a test") returns ==> "'This ''is'' a test'"

    Comment

    • StephanieCat
      New Member
      • Mar 2007
      • 5

      #3
      Thanks for the help!

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32633

        #4
        Apostophes should only be a problem in SQL strings as VBA uses the double-quote character for string delimiting.
        ADezii's solution is perfectly general purpose though. Nice.

        Comment

        Working...