简体   繁体   English

访问条件格式以获取单个记录上的连续表单

[英]Access Conditional Formatting for continuous form on individual records

I have a continuous form that list times that samples were taken and levels of different chemicals in those samples. 我有一个连续的表格,列出了采集样本的时间和这些样本中不同化学物质的水平。 I want to format the cells to show when a chemical level is out of range. 我想格式化细胞以显示化学物质水平何时超出范围。 My problem is, that they change for each sample time. 我的问题是,它们会在每个采样时间内发生变化。 .3 is way too high for a 10 hour sample, but is fine for 30 hours. .3对于10小时的样品来说太高了,但是30小时都没问题。 Below is an example of what my continuous form looks like. 下面是我的连续形式的示例。

Sample Time      Lactics      Sugar
10 hour           .085        15.2
20 hour           .125        12.8
30 hour           .345        8.4
40 hour           .405        4.2
50 hour           .415        1.9

So I want to say "if Lactics > .2 at 20 hour then make the cell red" and so on for each time period and each component I am tracking. 所以我想说“如果Lactics> .2在20小时然后让细胞变红”等等,每个时间段和我跟踪的每个组件。 How can I set this up with VBA? 如何使用VBA进行设置?

Create a table to hold your "out of range" rules. 创建一个表来保存“超出范围”的规则。

Sample Time Lactics_limit
10 hour                .3
20 hour               .35
30 hour                .4
40 hour               .45
50 hour                 ?

Then base your form on a query which joins your original table to the value_limits table, with a calculated field, lactics_flag , which indicates when the value is out of range. 然后将表单基于一个查询,该查询将原始表连接到value_limits表,并带有计算字段lactics_flag ,该字段指示值何时超出范围。 And base your conditional formatting on lactics_flag . 并将您的条件格式基于lactics_flag

SELECT
    y.[Sample Time],
    y.Lactics,
    y.Sugar,
    IIf(y.Lactics > v.Lactics_limit, True, False) AS lactics_flag
FROM
    YourTable AS y
    INNER JOIN value_limits AS v
    ON y.[Sample Time] = v.[Sample Time];

Compare the simplicity of that approach with the complexity of an Expression Is list you would need to express those same rules: 将该方法的简单性与Expression Is列表的复杂性进行比较,您需要表达相同的规则:

([Sample Time]="10 hour" And [Lactics]>0.3) Or ([Sample Time]="20 hour" And [Lactics]>0.35) Or ([Sample Time]="30 hour" And [Lactics]>0.4) Or ([Sample Time]="40 hour" And [Lactics]>0.45) Or ([Sample Time]="50 hour" And [Lactics]>?)

Another advantage of this approach is that it's easier to maintain your rules when they are stored in a table instead of as conditional formatting expressions in a form. 这种方法的另一个优点是,当它们存储在表中而不是作为表单中的条件格式表达式时,更容易维护规则。 And the rules could be easily re-used for other forms or reports. 规则可以很容易地重复用于其他表格或报告。

If you don't have rules for every [Sample Time] , you could leave them out of the value_limits table and use a LEFT JOIN in the query. 如果每个[Sample Time]都没有规则,则可以将它们从value_limits表中删除,并在查询中使用LEFT JOIN

You can use Expression Is wih a list of values: 您可以使用表达式是一个值列表:

 ([sample]=10 And [Lactics]>=0.2) Or ([sample]=20 And [Lactics]>=0.35)

条件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM