We help IT Professionals succeed at work.

How to make line break in CrystalReports?

Medium Priority
965 Views
Last Modified: 2013-11-26
Hello
I'm developing application in VB.NET
I have crated crystalReport with TextObject "Header".
Now I need to change text in "Header" based on what I get from database.
I also need to break the text in specified places.
So if I have in my database:     "This is my Header \n New line is here"
I need to break line on "\n"
I tried Replace("string", "\n",NewLine) but its not working.
How can I break line in crystalreport?

Best Regards
FooKy
Comment
Watch Question

Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008

Commented:
Have you tried to use all this:

Chr(10)
Chr(13)
or
VbCrLf

Senior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013
Commented:
When you say replace do you mean you will change the field on the fly or are you replacing it with a formula.

The CHR(10) or chr(13) should work to replace the \n.
Have you tried using the built in HATML display capability?

If you right click the field and click FORMAT FIELD
One of the options on the PARAGRAPH tab is TEXT INTERPRETATION.  Select HTML

mlmcc
CERTIFIED EXPERT

Author

Commented:
Hello,
Sorry for delay but there was a power cut-off in my neighbourhood due to strong winds.

Below I attach code with description of what I'm trying to do.

I also looked at format field -> paragraph tab but there was nothing about text interpretation (maybe because its not full version of CrystalReports but only this what is VS 2005 TeamSuite)
See screenshot.

Best Regards
FooKy
Dim rtxt As CrystalDecisions.CrystalReports.Engine.TextObject = CType(rpt1.ReportDefinition.ReportObjects.Item("TextHeader"), CrystalDecisions.CrystalReports.Engine.TextObject)
 
rtxt.Text = Replace(dr2("header"), "\n", vbNewLine)
'Also tryed 
rtxt.Text = Replace(dr2("header"), "\n", Chr(10) & Chr(13))
rtxt.Text = Replace(dr2("header"), "\n", "<br>")
rtxt.Text = Replace(dr2("header"), "\n", "<br />")
rtxt.Text = Replace(dr2("header"), "\n", vbCrLf)

Open in new window

paragraph.png
Jorge PaulinoIT Pro/Developer
CERTIFIED EXPERT
Top Expert 2008
Commented:
When I want to use text with breaks I always use parameter fields. Add a new parameter field and then do this:

Dim strFooter As String = "My text using breaks ..."
Dim rpt As New rptTest()
rpt.SetParameterValue("txtFooter", strFooter) 'txtFooter is the name of the parameter field in the report

jpaulino
CERTIFIED EXPERT

Author

Commented:
Thanks.
Both answers were accurate.
First i thought that mlmcc was taking about text object but TEXT INTERPRETATION is only in parameter field.
so I used it and code from jpaulino and replaced \n to

Best Regards
FooKy