Roger,
I made the following test:
Sub Test()
Dim rs As DAO.Recordset
Dim strCriteria(1 To 3) As String
Dim i As Integer
Set rs = CurrentDb.OpenRecordset("Data", dbOpenDynaset)
strCriteria(1) = "'apostrophe'"
strCriteria(2) = """quotation mark"""
strCriteria(3) = "'apostrophe' ""quotation mark"""
For i = 1 To 3
rs.FindFirst "Product='" & Replace(strCriteria(i), "'", """") & "'"
Debug.Print i & "; Found: " & Not rs.NoMatch
Next i
End Sub
All criterias are stored within the recordset, but only the 2nd criteria is
found. What am I doing wrong?
Tom
Roger Carlson said:
You could use the Replace function to replace one with the other in the
criteria string. For instance:
rst.FindFirst "Product='" & replace(strCriteria,"'", chr(34) )& "'"
or maybe
rst.FindFirst "Product='" & replace(strCriteria,"'", """" )& "'"
Which *should* replace all the apostophes with quotes. (I'm going from
memory here, so test please). Then you only need one version of the
FindFirst. This doesn't actually change the value of the field, just your
comparison string.
--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org
Tom said:
Ken
Thank you for your answer. I entered the following code:
If InStr(strCriteria, "'") = 0 Then
rst.FindFirst "Product='" & strCriteria & "'"
Else
rst.FindFirst "Product=""" & strCriteria & """"
End If
But how to solve this, when the product contains an apostrophe AND a
quotation mark?
Tom
.FindFirst "[FieldName] = 'WOLF BLASS ""YELLOW LABEL""-01'"
Double up the " characters in the text string. If you're using a variable
or
control as the source of the string:
.FindFirst "[FieldName] = '" & Replace(VariableName, Chr(34),
Chr(34)