详细带格式事件执行一次以上,每行事件、格式、详细

2023-09-09 21:24:36 作者:晴栀

这是我的code交替颜色行中的数据发生变化时。 因为我是研究一种反常现象,其中一条线没有改变,它应该我发现,访问被看的每一行不止一次。

为什么在看数据超过一次?

 私人小组Detail_Format(取消作为整数,FormatCount作为整数)

昏暗的测试作为字符串

如果ISNULL(Text158.Value)然后
    pubstrFirstDetaildata =
其他
    pubstrFirstDetaildata = Text158.Value
结束如果

如果pubstrFirstDetaildata<> pubstrLastDetaildata然后
    backcolorCount = backcolorCount + 1
    如果backcolorCountmod2 = 1,则
        Me.Detail.BackColor =缬氨酸(与& H与&EDEDED)
        Me.Box160.BackColor =缬氨酸(与& H与&EDEDED)
    其他
        Me.Detail.BackColor = vbWhite
        Me.Box160.BackColor = vbWhite
    结束如果

结束如果

如果ISNULL(Text158.Value)然后
    pubstrLastDetaildata =
其他
    pubstrLastDetaildata = Text158.Value
结束如果
Text177 = backcolorCount
结束小组
 

解决方案   

为什么在看数据超过一次?

所建议的参数列表中 FormatCount 参数,在格式的详细信息带可以发射一次以上的记录源给定行视作为报表被渲染会发生什么。例如,如果报告中有一个或多个组定义,这些群体已经保持在一起的一个再启用一种可能性可能是

格式事件触发第一次给定的行, 的报告继续渲染,后续行可能会导致本集团波及到下一个页面,所以 的报告开始新的一页,备份之类的开始格式再次那些行。 你是不是也收到了这条信息 原因竟然是

如果你想确保code。在格式事件仅每行执行一次,那么你可以把它放在一个如果FormatCount = 1,则块。

This my code to alternately color rows when the data changes. As i was researching an anomaly where a line did not change where it should i found that Access is looking at the each line more than once.

Why is it looking at the data more than once?

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)

Dim test As String

If IsNull(Text158.Value) Then
    pubstrFirstDetaildata = ""
Else
    pubstrFirstDetaildata = Text158.Value
End If

If pubstrFirstDetaildata <> pubstrLastDetaildata Then
    backcolorCount = backcolorCount + 1
    If backcolorCount Mod 2 = 1 Then
        Me.Detail.BackColor = Val("&H" & "EDEDED")
        Me.Box160.BackColor = Val("&H" & "EDEDED")
    Else
        Me.Detail.BackColor = vbWhite
        Me.Box160.BackColor = vbWhite
    End If

End If

If IsNull(Text158.Value) Then
    pubstrLastDetaildata = ""
Else
    pubstrLastDetaildata = Text158.Value
End If
Text177 = backcolorCount
End Sub

解决方案

Why is it looking at the data more than once?

As suggested by the FormatCount parameter in the argument list, the Format event of the Detail band can fire more than once for a given row in the Record Source depending on what happens as the report is being rendered. For example, if the report has one or more Groups defined and one of those groups has "Keep Together" enabled then one possibility might be that

the Format event fires the first time for a given row, as the report continues to render, subsequent rows can cause the group to spill over onto the next page, so the report starts a new page and "backs up" to the beginning of the group to Format those rows again.

If you want to ensure that the code in the Format event is only executed once per row then you can put it inside an If FormatCount = 1 Then block.