使用IF语句而不是条件格式

时间:2010-07-07 16:12:53

标签: sql ms-access vba

因为似乎我的条件格式化语句太大了:

([Panels] like '*IT_AMPH,*' or [Panels] like '*AMPH_SN,*' or [Panels] like '*AMPH_S,*') and
([Panels] like '*IT_BARB,*' or [Panels] like '*BARB_SN,*' or [Panels] like '*BARB_S,*') and
([Panels] like '*IT_BENZ,*' or [Panels] like '*BENZ_SN,*' or [Panels] like '*BENZ_S,*') and
([Panels] like '*IT_BUP,*' or [Panels] like '*BUP_SN,*' or [Panels] like '*BUP_S,*') and
([Panels] like '*IT_SOMA,*' or [Panels] like '*SOMA_SN,*' or [Panels] like '*SOMA_S,*') and
([Panels] like '*IT_FEN,*' or [Panels] like '*FEN_SN,*' or [Panels] like '*FEN_S,*') and
([Panels] like '*IT_MEP,*' or [Panels] like '*MEP_SN,*' or [Panels] like '*MEP_S,*') and
([Panels] like '*IT_METD,*' or [Panels] like '*METD_SN,*' or [Panels] like '*METD_S,*') and
([Panels] like '*MPH,*') and
([Panels] like '*IT_OPIA,*' or [Panels] like '*OPIA_SN,*' or [Panels] like '*OPIA_S,*') and
([Panels] like '*IT_OXYC,*' or [Panels] like '*OXY_SN,*' or [Panels] like '*OXY_S,*') and
([Panels] like '*IT_PROPX,*' or [Panels] like '*PROPX_SN,*' or [Panels] like '*PROPX_S,*') and
([Panels] like '*TAP,*' or [Panels] like '*TAP_SN,*' or [Panels] like '*TAP_S,*') and
([Panels] like '*IT_TRAM,*' or [Panels] like '*TRAM_SN,*' or [Panels] like '*TRAM_S,*') and
([Panels] like '*IT_TCA,*' or [Panels] like '*TCA_SN,*' or [Panels] like '*TCA_S,*') and
([Panels] like '*IT_COCN,*' or [Panels] like '*COCN_SN,*' or [Panels] like '*COCN_S,*') and
([Panels] like '*IT_6-MAM,*' or [Panels] like '*6-MAM_SN,*' or [Panels] like '*6-MAM_S,*') and
([Panels] like '*IT_MDMA,*' or [Panels] like '*MDMA_SN,*' or [Panels] like '*MDMA_S,*') and
([Panels] like '*IT_PCP,*' or [Panels] like '*PCP_SN,*' or [Panels] like '*PCP_S,*') and
([Panels] like '*IT_THC50,*' or [Panels] like '*THC_SN,*' or [Panels] like '*THC_S,*') and
([Panels] like '*ETOH_S,*' or [Panels] like '*ETOH,*') and
([Panels] like '*NIC,*') and
([Panels] like '*IT_ETG,*' or [Panels] like '*ETG_SN,*' or [Panels] like '*ETG_S,*')

我在想,也许我应该做一个IF陈述而不是条件格式化。例如,如果上述陈述为true,则将文本框字体颜色设置为黑色

我的问题是否有效?

如果我在上述语句中对IF执行Report_Load语句,它是否与条件格式一样有效?

如果是的话,那我该怎么办呢?请给我一些代码?

1 个答案:

答案 0 :(得分:1)

考虑在隐藏文本框的表达式中使用复杂条件。然后,您可以在简化的条件格式规则中引用隐藏文本框。

我创建了txtStatus作为隐藏文本框,将此表达式作为其控件源(foo_text是表单记录源中的字段):

=IIf([foo_text] Like 'child*',1,0)

然后,对于我显示的文本框,我为:

添加了一个条件“Expression Is”
[txtStatus]>0

...当条件为True时,为文本属性指定红色。

也许类似的方法对您有用。