Conditional Color of Report Object

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.
 
A

Allen Browne

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.
 
K

Ken Hudson

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.
 
K

Ken Hudson

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
 
A

Allen Browne

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top