Pass Multiple Line String In Crystal Report Formula From VB.Net

Here's how to pass a multi-line string from VB.Net to a Crystal Report in a formula. If you don't deal with this properly, you will get an error such as Error in Formula... The remaining text does not appear to be part of the formula because Crystal Reports thinks the first carriage return is the end of the formula.

This has taken me a little bit of fiddling about and it might save you some time so here it is. I wrap all this stuff up in classes but essentially all you need is this function to convert the line endings.

Private Function multiLineFormulaText(ByVal sMultilineString As String) As String

	Return "'" & sMultilineString.Replace("'", "''").Replace(vbCrLf, "' + Chr(13) + '") & "'"

End Function
		
Page Updated 08/06/10