Reputation: 2632
So, say I have the following string
THIS IS STUFF (MORE STUFF)
How would I get the string to format as such in a textbox in SSRS?
THIS IS STUFF
(MORE STUFF)
This data is pulled from a single field in a query and I will not be able to manually inject a break line.
Also, sometimes the (More Stuff) is not in the field.
Extra examples:
Upvotes: 5
Views: 17126
Reputation: 499
I came across this issue while doing my project. And I would like to share my steps for this. Create individual placehloders within the textbox by selecting the expression and format each as you desired. You can easily add extra line by just moving the another item(another placeholder) to next line(by pressing enter-on the keyboard)
Here I created individual placeholders inside the list, gave the names and format just as I want.
Upvotes: 0
Reputation: 39586
You need to insert a line break into the string, i.e. set the textbox expression as something like:
="THIS IS STUFF" & vbcrlf & "(MORE STUFF)"
So the expression in a single textbox:
Will render as:
You can see there is a line break even though the string could fit on one line.
Edit after comment
OK, we need to handle various existing strings at the report level.
To do this, I would suggest using Custom Code, i.e. a function like:
Function SplitString (fieldValue As String) As String
If IsDBNull(fieldValue) OrElse IsNothing(fieldValue) Then
SplitString = ""
Else If InStr(fieldValue, "(") > 0
SplitString = RTrim(Left(fieldValue, InStr(fieldValue, "(") - 1)) & _
vbcrlf & Right(fieldValue, Len(fieldValue) - InStr(fieldValue, "(") + 1)
Else
SplitString = fieldValue
End If
End Function
I'm suggesting this as SSRS expression are notoriously brittle, and the lack of short circuiting means that what works for one string might display #Error
on another. You could get around this with numerous IIf
statements but Custom Code is much neater and easier to understand.
You can call the function with an expression like:
=Code.SplitString(Fields!MYFIELD.Value)
Either in a textbox expression or as a Calculated Field in the Dataset. The above works for me on your data:
Upvotes: 6