tags:

views:

53

answers:

2

I have a datasheet that looks like this:

ID  name_   1   2   3   4
1   name1   x   0   0   0
2   name2   0   x   0   0
3   name3   0   0   x   0
4   name4   0   0   0   x

I have rectangles on a report that correspond to this datasheet.

When the report opens, I need the rectangles to be colored red according to the data. For example, in the name1 row where there is an x in the 1 column, I need the specific rectangle corresponding to this (name1, 1) to be colored red. Here is the result that I need:

x           
    x       
        x   
            x

(where x is a rectangle that is red)

Perhaps the best place to place this code would be in ON LOAD event of the report, but i am not sure exactly. Can you please suggest to me some code that would turn the specified rectangles red according to the data?

+5  A: 

Use conditional formatting, not code.

Remou
how do i do that in 2007?
I__
you cant use conditional formatting on a rectangle
I__
Why are you making them rectangles when they are displaying data (i.e., the "x")? They should be textboxes, and then you can use conditional formatting to color the background based on the value being "x". You seem to know the answer to the question based on the title of it, so, again, I question why you are posting in the first place.
David-W-Fenton
+1  A: 

In this case, I see no reason that @Remou's answer is not correct -- you want to display an x, which is data, so you would use a textbox with conditional formatting that sets the background color appropriately.

However, if you wanted to do this without a data control, you'd likely use the Format event of the Detail of the report. This is the event that fires when each record is processed, and it could be used to run a test that determines which rectangle to hide/show or what color to give the background of the rectangle.

The OnOpen runs before any of the data is loaded, and the OnLoad event before any particular rows are accessed. Because of that, neither is appropriate for formatting controls in individual rows of the report.

And BTW, your mention of the OnLoad in reports indicates that you're using Access 2007 or later (the event didn't exist for reports in A2003 and earlier), and you should have stated that in your question.

David-W-Fenton