Change table's text color based on it's value Folgen


I have a table built to mimic an Excel file when it prints.  It has a basic header line and then the dynamic data line below it.  I have the database connection setup to use an Excel file.  On one of the columns, I want the text to print red when it's a negative number.  I have the data source set to the correct column.  In the Excel file, it's a float or decimal number, but the column is set to be defined as US currency.  In BarTender, I have the Data Type set to Currency also.  It prints the information correctly.  However, I don't see an option to change the text color to red if it's a negative number.

I've tried the following code in Document Options / OnNewRecord.

If (Format.Objects("Text 32").Value < 0) Then

    Format.Objects("Text 32").TextColor = BtColor.Red

End If

I've even tried something more complicated like:

If (InStr(CStr(Format.Objects("Text 32").Value), "-") <> 0) Then

    Format.Objects("Text 32").TextColor = BtColor.Red

End If

But, the whole column of data is Red, whether the number is negative or positive.  Is there a better solution to this?

Thank you, thank you!!

1 Kommentare

Peter Thane
Aktionen für Kommentare Permalink

You could use conditional printing and 3 layers. 

  • Layer one would be your main layout and include (off the side of the label so it does not print) the data being read from the database and give this a name (via the Change Data Source Name button in the Properties of that field)
  • Layer 2 include only your black text field and set the "Print When" options to print when the value of the Named field is 0 or higher. This setting can be accessed by clicking on the properties of the layer
  • Repeat for layer 3 but with a red text field and "Print When" less than 0

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.