PDA

Click to See Complete Forum and Search --> : comma's are messing up my .Filter!


bboht
Aug 31st, 2000, 07:57 AM
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!!)

Stevie
Aug 31st, 2000, 08:38 AM
Before setting your filter, put strVar through a procedure such as ...


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 :)

Pedro de la Lastra
Aug 31st, 2000, 10:10 AM
rs.Filter = "Field = '" & Replace(strVar,"'","''") & "'"

This should work