Conditional Color of Report Object

  • Thread starter Thread starter Ken Hudson
  • Start date Start date
K

Ken Hudson

I want to set the background color of a report object based on a certian
condition.
If the object's value is > 0, I want to change the background color to yellow.
I assume that I need to use VBA in one of the report events, but I don't
know the code or event.
 
Assuming Access 2000 or later, you can just use Conditional Formatting (on
the Format menu, when the object is selected, in report design.)

Code will be slower, but if you want to do that, use the Format event of the
Section that the object is in (Detail?), to set its BackColor property.
 
I found the answer. I was looking somewhere in the properties and didn't
realize that the the menu bar has conditional formatting like Excel. I should
have looked in the help menu before posting here.
Apologies.
 
Thanks for the reply Allen.
What would the code be to make that happen?
I tried the Excel equivalent, but to no avail.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Act_GPM] < 1.6 Then
[Act_GPM].interior.Colorindex = 3
End Sub
 
Sounds like you have CF working (definitely the better way), but the code
would be like this:

With me.Act_GPM
If .Value < 1.6 Then
.BackColor = vbWhite
Else
.BackColor = vbYellow
End If
End With

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Ken Hudson said:
Thanks for the reply Allen.
What would the code be to make that happen?
I tried the Excel equivalent, but to no avail.

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Act_GPM] < 1.6 Then
[Act_GPM].interior.Colorindex = 3
End Sub

--
Ken Hudson


Allen Browne said:
Assuming Access 2000 or later, you can just use Conditional Formatting
(on
the Format menu, when the object is selected, in report design.)

Code will be slower, but if you want to do that, use the Format event of
the
Section that the object is in (Detail?), to set its BackColor property.
 
Back
Top