Export (0) Print
Expand All

How to: Add Code to a Report (Report Builder 3.0)

In Report Builder, you can add custom code written in Visual Basic directly in your report and then add a reference to it from any expression. During report processing, the code is processed. The namespaces for two Microsoft .NET Framework classes are automatically included: System.Math and System.Convert. Adding references to other classes is not supported in Report Builder.

When you are connected to a report server, report processing takes place on the report server. When you are not connected to a report server, report processing takes place on the client computer.

For more information about other references you can make from your code, see Using Custom Code References in Expressions (Report Builder 3.0).

NoteNote

Adding references to custom assemblies is supported only if you are connected to a report on a report server where the system administrator has installed the custom assemblies.

To add embedded code to a report

  1. In Design view, right-click the design surface outside the border of the report and click Report Properties.

  2. Click Code.

  3. In Custom code, type the code. Errors in the code produce warnings when the report runs. The following example creates a custom function named ChangeWord that replaces the word "Bike" with "Bicycle".

    Public Function ChangeWord(ByVal s As String) As String
       Dim strBuilder As New System.Text.StringBuilder(s)
       If s.Contains("Bike") Then
          strBuilder.Replace("Bike", "Bicycle")
          Return strBuilder.ToString()
          Else : Return s
       End If
    End Function
    
  4. The following example shows how to pass a dataset field named Category to this function in an expression:

    =Code.ChangeWord(Fields!Category.Value)
    

    If you add this expression to a table cell that displays category values, whenever the word "Bike" is in the dataset field for that row, the table cell value displays the word "Bicycle" instead.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft