问题描述
在尝试有条件地格式化MS Access 2007表单中的报告中的记录展示时,我遇到了麻烦.
我已经在Internet上进行搜索,并且看到很多同事指出,可以通过为报表中的详细信息"部分的事件实现"Detail_Paint()"方法的代码在单个记录中执行视觉更改.那些人说这样的事情会起作用:
Private Sub Detail_Paint()
val = CStr(Me.someTextBox.Value)
If val = "constraint" Then
Me.lineStrikethrough.BorderStyle = 0
End If
End Sub
问题在于,尽管在抛出Paint事件时读取语句 Me.someTextBox.Value 返回每个记录的值,但是写入语句 Me.lineStrikethrough.BorderStyle = 0 为我的报告中的每一条行写BorderType属性的值,不仅是关于尊重我从 someTextBox 字段读取其值的一条记录的行. /p>
谁能告诉我为什么会这样?如果这是正确的行为(尽管对我来说似乎不合适),我如何实现我的目标?
注意: lineStrikethrough 用于对报表中的记录执行删除线效果.如果还有另一种方法,我很高兴知道.
您真的很亲密! :-)在我的测试中,看来Detail_Paint()
事件允许您更改控件的格式,但是更改 将在后续记录中继续 ,直到您更改/重置他们去别的东西.
在代码示例中,您只需要添加另一行即可在不再满足条件时重新打开删除线BorderStyle
.
Private Sub Detail_Paint()
Val = CStr(Me.someTextBox.Value)
If Val = "constraint" Then
Me.lineStrikethrough.BorderStyle = 0
Else
Me.lineStrikethrough.BorderStyle = 1
End If
End Sub
我在 MSDN上的代码示例,该示例演示了使用Detail_Paint()
方法的条件格式.
I am having a trouble while trying to conditionally format the exhibition of records in a report inside a MS Access 2007 form.
I have search the Internet and I have seen lots os fellows stating that it is possible to perform visual changes in a single record via code implementing the method Detail_Paint() for the event Paint of the Detail section in a Report. Those people say that something like this is going to work:
Private Sub Detail_Paint()
val = CStr(Me.someTextBox.Value)
If val = "constraint" Then
Me.lineStrikethrough.BorderStyle = 0
End If
End Sub
The problem is that although the reading statement Me.someTextBox.Value returns the value of each record when the Paint event is thrown, the writing statement Me.lineStrikethrough.BorderStyle = 0 writes the value of the property BorderStyle for every single line in my report, not only for the one respecting the single record whose value I read from someTextBox field.
Can anyone tell me why such is happening? If this is the correct behaviour (although it does not seem right to me), how can I achieve my goal?
Note: lineStrikethrough is used to perform a strikethrough effect over the record in a Report. If there is another way to do that I would be happy to know.
You are really close!! :-) In my testing, it appears that the Detail_Paint()
event allows you to change the formatting of controls, but changes will continue in subsequent records until you change/reset them to something else.
In your code sample, you just need to add another line to turn the strikethrough BorderStyle
back on when the condition is no longer met.
Private Sub Detail_Paint()
Val = CStr(Me.someTextBox.Value)
If Val = "constraint" Then
Me.lineStrikethrough.BorderStyle = 0
Else
Me.lineStrikethrough.BorderStyle = 1
End If
End Sub
I found this clue on a code sample on MSDN which demonstrates conditional formatting using the Detail_Paint()
method.
这篇关于通过VBA MS Access报告进行条件格式设置不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!