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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
jamaussConnect With a Mentor Commented:
Ok. Glad I could help.
0
 
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
All Courses

From novice to tech pro — start learning today.