You can change a report field's format based on its value by specifying an expression for the Detail section's OnFormat property.
To specify an expression for the OnFormat property, complete the following steps:
The following expression changes the UnitsInStock field's ForeColor to red if the sum of the UnitsInStock value and the UnitsOnOrder value is less than the ReorderLevel value. There are several ways to write this expression.
Option 1:
UnitsInStockCtl.Forecolor = Iif(UnitsInStock + UnitsOnOrder < ReorderLevel, vbRed, vbBlack)
Option 2:
lowStock = UnitsInStock + UnitsOnOrder < ReorderLevel
UnitsInStockCtl.Forecolor = Iif(lowStock, vbRed, vbBlack)
Option 3:
If UnitsInStock + UnitsOnOrder < ReorderLevel Then
UnitsInStockCtl.Forecolor = vbRed
Else
UnitsInStockCtl.Forecolor = vbBlack
End If
Option 4:
color = Iif(UnitsInStock + UnitsOnOrder < ReorderLevel, vbred, vbblack)
UnitsInStockCtl.Forecolor = color
Notice that the Outback Lager's UnitsInStock value is formatted in red since the sum of the UnitsInStock and UnitsOnOrder is less than the ReorderLevel.