ACC2: Cannot Search for Name with Apostrophe in Find CustomersID: Q121260
|
Moderate: Requires basic macro, coding, and interoperability skills.
When you are using the Find Customers form in the sample database
SOLUTION.MDB, you cannot search for a customer whose name contains an
apostrophe ('). For example, if you try to search for a customer with the
name "B's Foods," you receive the following error message:
Syntax error in query expression '[Company Name] Like 'B's Foods*''
This article assumes that you are familiar with Access Basic and with
creating Microsoft Access applications using the programming tools provided
with Microsoft Access. For more information on Access Basic, please refer
to the "Building Applications" manual.
The following steps demonstrate how to modify the AddToWhere Sub procedure
so that you can search for customer names containing apostrophes.
NOTE: In the following sample code, an underscore (_) at the end of a line
is used as a line-continuation character. Remove the underscore from the
end of the line when re-creating this code in Access Basic.
Mycriteria = (Mycriteria & FieldName & " Like " & Chr(39) & _
Fieldvalue & Chr(42) & Chr(39))
If InStr(1, fieldvalue, "'") Then
Mycriteria = (Mycriteria & FieldName & " Like " & Chr(39) &
Left(Fieldvalue, InStr(1, Fieldvalue, "'") - 1) & "'" & _
Mid(Fieldvalue, InStr(1, Fieldvalue, "'")) & Chr(42) & Chr(39))
Else
Mycriteria = (Mycriteria & FieldName & " Like " & Chr(39) & _
Fieldvalue & Chr(42) & Chr(39))
End If
Keywords : kbusage FmsEvnt
Version : 2.0
Platform : WINDOWS
Issue type : kbprb
Last Reviewed: April 7, 1999