【发布时间】:2016-10-16 14:20:27
【问题描述】:
我有一个包含步骤列表文本框的报告。我需要根据基于查询的特定条件使用 VBA 代码调整它的背景颜色。我已经在详细信息面板的“On Format”下设置了代码。如果我调出一个步骤,它将改变步骤的颜色。如果我调用多个步骤,它只会突出显示最后一个框。对于测试,我有一个包含 13 个步骤的报告,但我想更改第 1 步和第 4 步。这是我使用的代码:
If DCount("*", "qry_step_check1") = 1 And Reports![rpt_WI_BOOK]![qry_Select_Step_Filter_Task].Report![Step].Value = 1 Then
[Reports]![rpt_WI_BOOK]![qry_Select_Step_Filter_Task].Report![Step].BackColor = lngYellow
Else
[Reports]![rpt_WI_BOOK]![qry_Select_Step_Filter_Task].Report![Step].BackColor = lngWhite
End If
If DCount("*", "qry_step_check4") = 1 And Reports![rpt_WI_BOOK]![qry_Select_Step_Filter_Task].Report![Step].Value = 4 Then
[Reports]![rpt_WI_BOOK]![qry_Select_Step_Filter_Task].Report![Step].BackColor = lngYellow
Else
[Reports]![rpt_WI_BOOK]![qry_Select_Step_Filter_Task].Report![Step].BackColor = lngWhite
End If
在这种情况下,只有第 4 步发生了变化。如果我删除第 4 步的列表,第 1 步将突出显示。在这一点上,我不确定我正在做的事情是否有效,或者我只是错过了一些简单的事情。我也尝试过使用 DLookups 并获得相同的结果。我知道代码可能不是最有效的,但在这一点上,我只是想让它发挥作用,以后可以担心更高效的代码。这是我正在使用的设计视图的快速截图。
【问题讨论】:
标签: ms-access vba ms-access-2010 ms-access-2013