|
本帖最后由 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
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|