Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Textbox Formatting In SSRS 2008 - Break Line

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:

  • STUFF AND THINGS
  • THINGS (STUFF)
  • THINGS AND STUFF (MORE STUFF)
  • like image 506
    Elias Avatar asked Oct 02 '13 16:10

    Elias


    People also ask

    How do you break a line in SSRS expression?

    When you need to include a line break within a textbox in SQL Server Reporting Services, a predefined Visual Basic constant may be used. The vbcrlf, Visual Basic Carriage Return Line Feed, handles this quite nicely within an SSRS expression.

    How do you add a new line in SSRS expression?

    Using Newline functionMake use of Environment. NewLine() function to add line break within the expression.

    How do I add a space in SSRS report?

    If you want to fix it, you can add a rectangle control and then fix your boxes with required space inside it. About the extra blank paper at the end, it happens when your controls exceed the dimensions of the report. Search for it, you'll find many helpful articles.

    How do you set expressions in SSRS report?

    In Design view, click the text box on the design surface to which you want to add an expression. For a simple expression, type the display text for the expression in the text box. For example, for the dataset field Sales, type [Sales] . For a complex expression, right-click the text box, and select Expression.


    1 Answers

    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:

    enter image description here

    Will render as:

    enter image description here

    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:

    enter image description here

    enter image description here

    like image 74
    Ian Preston Avatar answered Sep 28 '22 04:09

    Ian Preston