I'm trying to make a field on a report highlight in red with white bold font on a report when it has an "S" populated. This keeps making all records in the field red. Please help!
Private Sub Report_Activate()
If Me![PULL STATUS] = "S" Then
Me![PULL STATUS].BackColor = vbRed
Me![PULL STATUS].FontBold = True
Me![PULL STATUS].ForeColor = vbWhite
End If
End Sub
The code you have should be contained in the On Format event of the Detail section of the report. When you set the BackColor
, FontBold
, and ForeColor
it stays that way until it is changed again.
So what you need is an else statement to perform the opposite if not true. Something like:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me![PULL STATUS] = "S" Then
Me![PULL STATUS].BackColor = vbRed
Me![PULL STATUS].FontBold = True
Me![PULL STATUS].ForeColor = vbWhite
Else
Me![PULL STATUS].BackColor = vbWhite
Me![PULL STATUS].FontBold = False
Me![PULL STATUS].ForeColor = vbBlack
End If
End Sub
MS Access uses Conditional Formatting - much like MS Excel; I recommend this instead of using VBA to change the backcolor pragmatically. This should work well for 'Continuous Forms.'