Click here to Skip to main content
15,905,558 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim rs As Object
Set rs = Me.Recordset.Clone

    rs.FindFirst "[Name] = '" & Me![Combo81] & "'"
    If Not rs.EOF Then Me.Bookmark = rs.Bookmark


The above code is used to check for the combo box to search
for name without any quotes .

I need to have a conditon weather the name has apostrophe,quotes or not .

1)How do I check weather the name has any sort of quotes or not ?

2)How can I write the above code for the same ,if the name conatins
->single quotes ('')
->double quotes ("")
->apostrophe(')

Thanks
Posted
Updated 29-May-12 1:46am
v4
Comments
OriginalGriff 24-May-12 5:42am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

1 solution

Refer this link.. It is dealing with the situation you are asking for.. I all also put an updated solution once I get the code working

http://support.microsoft.com/kb/113955


Here is the code

First write two small helper functions to replace the single quote and double quote with chr(39) and chr(34)

VB
Function DoParseQuote(ByVal sString As String) As String
    Dim sTemp As String
    sTemp = Replace(sString, "'", "' & Chr(39) & '")
    DoParseQuote = sTemp
End Function

Function DoParseDoubleQuote(ByVal sString As String) As String
    Dim sTemp As String
    sTemp = Replace(sString, """", "' & Chr(34) & '")
    DoParseDoubleQuote = sTemp
End Function


Then call the function from search

VB
str = "EmpName = '" & DoParseQuote("Don't") & "'"
str = "EmpName = '" & DoParseDoubleQuote("Milka ""speedy"" singh") & "'"

rs.FindFirst str
 
Share this answer
 
v2
Comments
Maciej Los 24-May-12 6:39am    
Good link and answer, my 5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900