Conditional formatting using a script

Using a report script, you can format report fields based on a condition (comparison). This allows you to, for example, emphasize certain data in a report.

For formatting fields, the following properties are available:

  • Bold (bold)
  • Italic (italics)
  • Name (font name)
  • Size (font size)
  • Strikethrough (struck through)
  • Underline (underlined)
  • ForeColor (text colour)

For formatting labels and text fields, the following properties are available:

  • BackColor (background colour)
  • Font (font)

    Example:

    To make a field bold:

    {Element:Label1}.Font.Bold = True

    To set a field to a red font (using RGB values):

    {Element:Label1}.ForeColor = RGB(255, 0, 0)

    To set a field to a red font (using a VB code):

    {Element:Label1}.ForeColor = vbRed

If you increase the font size or make a field bold, the field may take up more space. Take this into account when creating the report.

Conditional formatting using a script:

In this example you add a script that prints an average in bold and blue if it is greater than 1000.

  1. Click on:.

    Profit opens the script editor.

  2. Open the Detail section / Print heading.

    Profit opens a new window for scripts in the document footer.

  3. Drag the  {Element:VeldGemiddelde} field to the script box.

  1. Enter the following script:

    If DecComp({Element:VeldGemiddelde},1000)= 1 then

     {Element:VeldGemiddelde}.Font.Bold = true

     {Element:VeldGemiddelde}.Forecolor = vbBlue

    else

      {Element:VeldGemiddelde}.Font.Bold = false

    end if

    You can use the 'DecComp' function to compare two values. If the first value is greater than the second one, the result of this function is the value 1 and the field will be made bold.

  2. Click on: OK.
  3. Click on: Close.
  4. Press: F7. or go to Document / Print preview.

To test fields and format another field:

In the example above, a field is tested and then gets a format. This only works if the field being tested contains a value.

You can test whether a field has a value using 'IsEmpty'.

If IsEmpty({Element:VeldGemiddelde}.Value) Then

{Element:VeldNaam}.BackColor = vbYellow

End If

Directly to

  1. Report script
  2. Complete a function field
  3. Conditional formatting
  4. Hide detail section lines