How to display a simple calculated field in a report

It's sometimes convenient to be able to display a simple custom calculated field in a report without having to depend on a data source (existing or not). Report fields, which are similar to those used in Microsoft Word allow to do exactly that.
  1. Insert a DOCVARIABLE field anywhere you like in the report, this field will be replaced with the custom value at run-time. In order to insert the field, just click Ctrl+F9, the field symbol {} will appear with the insertion cursor in the middle. Then enter the following { DOCVARIABLE "Field1" }, you can then switch back to viewing the field results on the View tab.
  2. Switch to code view and implement the CalculateField event as illustrated in the code sample below. After this is done, every time the report template is used, the macro will run to define Field1.
Public Class Report1

    Private Sub ThisReport_CalculateField(ByVal source As Object, ByVal args As MediaCy.Addins.Reporter.CalculateFieldEventArgs) Handles ThisReport.CalculateField
         If args.FieldName = "Field1" Then
        End If
    End Sub

End Class
Sign In or Register to comment.