VB-Crystal Report

I need to pass the criteria for a crystal report through VB and the criteria contains a person name which has an "'" in the name, ex: O'Neil. I tried by using 'char(XX)' instead "'", but it didn't work. Any suggestions Pl?
ravinkAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jamaussCommented:
you should use replace function to convert a "'" to "''"

dim newstr
newstr = replace(originalstr, "'", "''")


If that doesn't work here's a function that will work.

Public Function RepQ(ByVal MyString)
 Dim strTemp As String
 Dim iStart As Integer
 Dim iNew As Integer

 iStart = 1
 strTemp = ""

 iNew = InStr(iStart, MyString, "'")
 If iNew = 0 Then
 RepQ = MyString
 Exit Function
 End If

Do While iNew
 strTemp = strTemp & Mid(MyString, iStart, (iNew - iStart)) & "''"
 iStart = iNew + 1
 iNew = InStr(iStart, MyString, "'")
Loop
 'replace remaining characters
strTemp = strTemp & Mid(MyString,iStart)
 RepQ = strTemp

End Function

0
ravinkAuthor Commented:
I need to pass the value for one of the field in Crystal Report. If i try to pass the value it contains three quotes as the value contains one quote. So it returns me an error. I dont want to replace the quote with double quotes. Is there anyway that I can use char built in function or anything that allows me use quote in the name. ex:O'Neil.
0
jamaussCommented:
Are you sending the criteria to Crystal Reports from VB through an SQL statement set into a dynaset or shanpshot recordset or what?

The reason I gave you code to convert a single "'" into a double "''" is because a database engine's SQL interprets a "''" as "'" in names so it should work. Otherwise, like you stated earlier, it will give you an error message because the single "'" in the name ends the SQL criteria. Did you try sending your criteria (The name with a "'" in it) through the function and see if it worked?
0
ravinkAuthor Commented:
THanks jamauss
  It worked. Please answer again, so that I will accept.
0
jamaussCommented:
Ok. Glad I could help.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.