开发者

Conditional formatting in Access

开发者 https://www.devze.com 2023-01-01 04:33 出处:网络
I have a datasheet that looks like this: IDname_1234 1name1x000 2name20x00 3name300x0 4name4000x I have rectangles on a report that correspond to this datasheet.

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开发者_StackOverflow中文版 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?


Use conditional formatting, not code.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消