Office中国论坛/Access中国论坛

标题: 报表预览和打印的数据不一致 [打印本页]

作者: VulcanTerry    时间: 2013-1-11 13:11
标题: 报表预览和打印的数据不一致
本帖最后由 VulcanTerry 于 2013-1-11 14:18 编辑

       应用中设计的统计报表,由于要汇总的数据需要引用其他表的字段值,于是参考论坛中“分页合计”的方法,汇总数据不是字段的合计"sum(字段)",而是VBA代码生成的汇总数据。报表数据在预览中显示正确,但通过预览右键菜单打印的报表,得到的数据会比正确数据大一倍。

        附件中,打印报表的窗体名是“frmProductMain”,通过预览后,打印或导出PDF文件,最后的总计数量都会翻一倍,冏。

        报表的VBA代码如下:
Option Compare Database
Option Explicit

Private curTotalBal, curTotalIn, curTotalOut, curTotalInv, curSumBal, curSumIn, curSumOut, curSumInv As Currency

Private Sub Report_Open(Cancel As Integer)
    Me.Caption = dtmStartDate & "至" & dtmEndDate & "商品库存表"
End Sub

Private Sub 报表页脚_Print(Cancel As Integer, PrintCount As Integer)
    Me.txtTotalBal = curTotalBal
    Me.txtTotalIn = curTotalIn
    Me.txtTotalOut = curTotalOut
    Me.txtTotalInv = curTotalInv
End Sub

Private Sub 报表页眉_Print(Cancel As Integer, PrintCount As Integer)
    curTotalBal = 0
    curTotalIn = 0
    curTotalOut = 0
    curTotalInv = 0
End Sub

Private Sub 主体_Print(Cancel As Integer, PrintCount As Integer)
    curSumBal = curSumBal + Me.txtBal
    curSumIn = curSumIn + Me.txtIn
    curSumOut = curSumOut + Me.txtOut
    curSumInv = curSumInv + Me.txtInv
End Sub

Private Sub 组页脚0_Print(Cancel As Integer, PrintCount As Integer)
    Me.txtSumBal = curSumBal
    Me.txtSumIn = curSumIn
    Me.txtSumOut = curSumOut
    Me.txtSumInv = curSumInv
    curTotalBal = curTotalBal + Me.txtSumBal
    curTotalIn = curTotalIn + Me.txtSumIn
    curTotalOut = curTotalOut + Me.txtSumOut
    curTotalInv = curTotalInv + Me.txtSumInv
End Sub

Private Sub 组页眉0_Print(Cancel As Integer, PrintCount As Integer)
    curSumBal = 0
    curSumIn = 0
    curSumOut = 0
    curSumInv = 0
End Sub


作者: todaynew    时间: 2013-1-11 14:04
用Dsum求和不就完事了
作者: VulcanTerry    时间: 2013-1-11 14:13
todaynew 发表于 2013-1-11 14:04
用Dsum求和不就完事了

呵呵,谢谢支持




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3