Results 1 to 3 of 3

Thread: comma's are messing up my .Filter!

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2000
    Posts
    35
    recset.Filter = "TITLE = '" & strVar & "'"

    if strVar has a ' or a " it bombs out. Is there a way around this, other than physicaly taking the 's and "s out of the string? (if I do that the filter won't filter properly!!)

  2. #2
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    Before setting your filter, put strVar through a procedure such as ...

    Code:
    Public Sub InsertSingleQuote(SourceString As String)
    '***************************************************************************
    'Purpose:     Replaces single single quotes with double single quotes.
    'Parameters:  SourceString - String to be formatted.
    'Returns:     None.
    '***************************************************************************
    On Error GoTo ErrorHandler
    
      SourceString = Replace(SourceString, "'", "''")
    
    Procedure_Exit:
      Exit Sub
        
    ErrorHandler:
      Select Case Err.Number
      
        Case Else
          GlobalErr Err.Number, Err.Description, "basUtilities - InsertSingleQuote"
          Resume Procedure_Exit
          Resume
      
      End Select
    
    End Sub
    Hope this helps
    VB6 sp5, SQL Server 2000, C#

    There are no stupid questions. Only stupid people.

  3. #3
    New Member
    Join Date
    Aug 2000
    Posts
    4

    You Should do this

    rs.Filter = "Field = '" & Replace(strVar,"'","''") & "'"

    This should work
    Ing. Pedro de la Lastra

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width