Skip to content

Changing Control Color for Certain Criteria on a Report

How to change the color of a specific control on a report.

Q: Huber Stevan wants to know whether there is a way to change the color of a specific control on a report record by record, depending on whether certain criteria are met.

A: For a report, this can be done in all Access versions using code in the report’s Format event, such as the following:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

 

   If Me![Sales] >= 10000 Then

      Me![txtSales].FontBold = True

      Me![txtSales].FontName = “Arial Black”

      Me![txtSales].FontSize = 12

      Me![txtSales].ForeColor = vbRed

      Me![txtSales].BackColor = vbYellow

      Me![imgGoldStar].Visible = True

   Else

      Me![txtSales].FontBold = False

      Me![txtSales].FontName = “Arial”

      Me![txtSales].FontSize = 9

      Me![txtSales].ForeColor = vbBlack

      Me![txtSales].BackColor = vbWhite

      Me![imgGoldStar].Visible = False

   End If

     

End Sub

If you have Access 2000 or higher, you can use Conditional Formatting (a new feature for Access 2000) to apply conditional formatting to controls (both on forms and reports).  In Design view, select the control, then select Format|Conditional Formatting, and set the condition and formatting as desired. 

About this author

Office 2024 - all you need to know. Facts & prices for the new Microsoft Office. Do you need it?

Microsoft Office upcoming support end date checklist.