Access 中的条件格式 [英] Conditional formatting in Access

查看:174
本文介绍了Access 中的条件格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个如下所示的数据表:

ID 名称_ 1 2 3 41 名称1 x 0 0 02 名称2 0 x 0 03 名称3 0 0 x 04 名称4 0 0 0 x

我在报告上有与此数据表相对应的矩形.

当报告打开时,我需要根据数据将矩形涂成红色.例如,在1列中有一个xname1行,我需要这个(name1, 1) 为红色.这是我需要的结果:

xXXX

(其中 x 是一个红色的矩形)

也许放置此代码的最佳位置是报告的 ON LOAD 事件,但我不确定.您能否向我建议一些可以根据数据将指定矩形变为红色的代码?

解决方案

在这种情况下,我认为@Remou 的答案没有理由不正确——您想显示一个 x,即数据,因此您可以使用带有条件格式的文本框,可以适当地设置背景颜色.

但是,如果您想在没有数据控件的情况下执行此操作,您可能会使用报表详细信息的格式事件.这是在处理每条记录时触发的事件,它可用于运行确定要隐藏/显示哪个矩形或为矩形提供背景颜色的测试.

OnOpen 在加载任何数据之前运行,并且在访问任何特定行之前运行 OnLoad 事件.正因为如此,两者都不适合在报表的各个行中格式化控件.

顺便说一句,您在报告中提到 OnLoad 表明您使用的是 Access 2007 或更高版本(A2003 及更早版本中的报告不存在该事件),您应该在问题中说明这一点.

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?

解决方案

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.

这篇关于Access 中的条件格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆