ACC: Using Find Method to Find a Quotation Mark or ApostropheID: Q104823
|
Advanced: Requires expert coding, interoperability, and multiuser skills.
This article demonstrates how to use the Find method to search for text
strings containing quotation marks (") or apostrophes ('). Searching for
text strings containing these characters requires special syntax because
the quotation mark and the apostrophe are used as delimiters in Access
Basic.
Function FindaPost1 ()
Dim MyDB As Database, MyDynaset As Dynaset
Set MyDB = CurrentDB()
Set MyDynaset = MyDB.CreateDynaset("Customers")
'Find this company.
MyDynaset.FindFirst "[company name]='Around the Horn'"
If Not MyDynaset.nomatch Then
MsgBox MyDynaset.[company name]
Else
MsgBox "No Match"
End If
MyDynaset.Close
End Function
Function FindaPost2 ()
Dim MyDB As Database, MyDynaset As Dynaset
Set MyDB = CurrentDB()
Set MyDynaset = MyDB.CreateDynaset("Customers")
'The following line will generate an error.
MyDynaset.FindFirst "[company name]='Babu Ji's Exports'"
If Not MyDynaset.nomatch Then
MsgBox MyDynaset.[company name]
Else
MsgBox "No Match"
End If
MyDynaset.Close
End Function
Function FindaPost3 ()
Dim MyDB As Database, MyDynaset As Dynaset
Set MyDB = CurrentDB()
Set MyDynaset = MyDB.CreateDynaset("Customers")
'Find this company (with an apostrophe in the name).
MyDynaset.FindFirst "[company name]=""Babu Ji's Exports"""
If Not MyDynaset.nomatch Then
MsgBox MyDynaset.[company name]
Else
MsgBox "No Match"
End If
MyDynaset.Close
End Function
Function FindQuote1 ()
Dim MyDB As Database, MyDynaset As Dynaset
Set MyDB = CurrentDB()
Set MyDynaset = MyDB.CreateDynaset("Employees")
'the following line generates a compile error.
MyDynaset.FindFirst "[notes] like '*"The art of the cold_
call."*'"
If Not MyDynaset.nomatch Then
MsgBox MyDynaset.[Last Name]
Else
MsgBox "No Match"
End If
MyDynaset.Close
End Function
Function FindQuote2 ()
Dim MyDB As Database, MyDynaset As Dynaset
Set MyDB = CurrentDB()
Set MyDynaset = MyDB.CreateDynaset("Employees")
'find this note that contains a quote.
MyDynaset.FindFirst "[notes] like '*" & Chr(34) & "The art of_
the cold call." & Chr(34) & "*'"
If Not MyDynaset.nomatch Then
MsgBox MyDynaset.[Last Name]
Else
MsgBox "No Match"
End If
MyDynaset.Close
End Function
For more information about the Find method, search for "find method" using the Microsoft Access Help menu.
Keywords : kbprg
Version : 1.0 1.1 2.0
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: March 26, 1999