We have a requirement to search the 'CODE' field within an Access database where the 'CODE' field may contain one or more instances of either single or double quotes. The data that is put in this field comes from an external source and we are unable to change its format. The data is also used when referring back to its source, so we cannot remove the single/double quotes on import.
My basic question is how do I make this work when using a Dynaset? We know that we can use either SQL or a snapshot, both of which work, however for various reasons neither of those methods is an option.
Below is some sample code that demonstrates the problem:
The table within the database contains two fields 'CODE' and 'NAME' where code is the primary key. Both fields are alphanumeric. Add a record to the table where 'CODE' = "o'sul" (no double quotes) and 'NAME' = "o'sullivan".
Set rs = db.OpenRecordset("Business Partners",_ dbOpenDynaset)
rs.FindFirst "Code = 'o''sul'"
If rs.NoMatch Then
Debug.Print "Dynaset Not Found"
Else
Debug.Print "Dynaset Found"
End If
Note that this will always return 'Dynaset Not Found' for the data example given above, whereas:
Set rs = db.OpenRecordset("SELECT * FROM [Business Partners] WHERE Code='o''sul'", dbOpenDynaset)
If Not rs.BOF And Not rs.EOF Then
Debug.Print "SQL Found"
End If
AND
Set rs = db.OpenRecordset("Business Partners",_ dbOpenSnapshot)
rs.FindFirst "Code = 'o''sul'"
If rs.NoMatch Then
Debug.Print "Snapshot Not Found"
Else
Debug.Print "Snapshot Found"
End If
always return "SQL found" or "Snapshot Found".
My basic question is how do I make this work when using a Dynaset? We know that we can use either SQL or a snapshot, both of which work, however for various reasons neither of those methods is an option.
Below is some sample code that demonstrates the problem:
The table within the database contains two fields 'CODE' and 'NAME' where code is the primary key. Both fields are alphanumeric. Add a record to the table where 'CODE' = "o'sul" (no double quotes) and 'NAME' = "o'sullivan".
Set rs = db.OpenRecordset("Business Partners",_ dbOpenDynaset)
rs.FindFirst "Code = 'o''sul'"
If rs.NoMatch Then
Debug.Print "Dynaset Not Found"
Else
Debug.Print "Dynaset Found"
End If
Note that this will always return 'Dynaset Not Found' for the data example given above, whereas:
Set rs = db.OpenRecordset("SELECT * FROM [Business Partners] WHERE Code='o''sul'", dbOpenDynaset)
If Not rs.BOF And Not rs.EOF Then
Debug.Print "SQL Found"
End If
AND
Set rs = db.OpenRecordset("Business Partners",_ dbOpenSnapshot)
rs.FindFirst "Code = 'o''sul'"
If rs.NoMatch Then
Debug.Print "Snapshot Not Found"
Else
Debug.Print "Snapshot Found"
End If
always return "SQL found" or "Snapshot Found".