访问VBA If语句以更改报表字段的“返回”和“字体”颜色 [英] Access VBA If statement to Change Back and Font color of a report field
本文介绍了访问VBA If语句以更改报表字段的“返回”和“字体”颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在报告中以红色填充并在报告中填充白色 S的白色加粗字体。这会使字段中的所有记录保持红色。请帮忙!
I'm trying to make a field on a report highlight in red with white bold font on a report when it has an "S" populated. This keeps making all records in the field red. Please help!
Private Sub Report_Activate()
If Me![PULL STATUS] = "S" Then
Me![PULL STATUS].BackColor = vbRed
Me![PULL STATUS].FontBold = True
Me![PULL STATUS].ForeColor = vbWhite
End If
End Sub
推荐答案
报告中的 Detail 部分的 按格式 事件应包含您拥有的代码。设置 BackColor
, FontBold
和 ForeColor
时保持这种方式,直到再次更改为止。
The code you have should be contained in the On Format event of the Detail section of the report. When you set the BackColor
, FontBold
, and ForeColor
it stays that way until it is changed again.
因此,您需要的是else语句,如果不是,则执行相反的操作。
So what you need is an else statement to perform the opposite if not true. Something like:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If Me![PULL STATUS] = "S" Then
Me![PULL STATUS].BackColor = vbRed
Me![PULL STATUS].FontBold = True
Me![PULL STATUS].ForeColor = vbWhite
Else
Me![PULL STATUS].BackColor = vbWhite
Me![PULL STATUS].FontBold = False
Me![PULL STATUS].ForeColor = vbBlack
End If
End Sub
这篇关于访问VBA If语句以更改报表字段的“返回”和“字体”颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文