【发布时间】:2016-08-31 15:45:30
【问题描述】:
我将 VBA 添加到我的报告中以在发票中包含空白行,此代码来自 here。打印预览向我显示了我想要的空白行,但是当我想将其导出为 PDF 或打印报告时,它会显示不可见的文本(而不是仅在空白行中)。我编辑了原始代码以重置增量编号,但这仅在从报告视图切换到打印预览时才有效(问题也在这里,我想在打印或导出时它也会重新查询报告,因此问题将得到解决,但无济于事)。
这是给我空白行的代码:
Option Compare Database
Option Explicit
Const iLines As Integer = 15
Private iTotal As Integer
' code added to make count able to reset on report load
Private iLine As Integer
Private Sub Report_Open(Cancel As Integer)
' get total record count
iTotal = DCount("*", "OrderLine", "fkOrderID = " & TempVars!tempOrderID)
' code added to reset count
iLine = 0
End Sub
Private Sub Details_Format(Cancel As Integer, _
FormatCount As Integer)
' code added to reset visibility
Me!Item.Visible = True
Me!qty.Visible = True
Me!CalcPrijs.Visible = True
Me!TotPrijs.Visible = True
' increment iLine on each detail format
iLine = iLine + 1
If iLine < iTotal Then
' do nothing ... print as usual
ElseIf iLine = iTotal Then
' if there are more lines to print, set the
' NextRecord property to false, preventing
' the report from exiting prematurely
If iLine < iLines Then Me.NextRecord = False
Else
' changed this to make text invisible instead of white
Me!Item.Visible = False
Me!qty.Visible = False
Me!CalcPrijs.Visible = False
Me!TotPrijs.Visible = False
' prevent report from advancing past last row
' until all of blank lines has have printed
If iLine < iLines Then Me.NextRecord = False
End If
End Sub
我在这里遗漏了什么吗?我希望一个好看的打印预览能给我一个好看的打印输出。有没有办法在不丢失打印输出数据的情况下获得额外的空白行?我添加了几张图片来说明我想要什么。
【问题讨论】:
-
我也尝试了here的方法,但我遇到了同样的问题。
-
你好,你能在
Details_Formatsub 的顶部放一个 debug.print "I'm going here" 并再次尝试打印操作吗?似乎在调用打印操作时未调用此子程序,仅在触发 Open 事件时才调用此子程序。您可能需要在要打印的 Sub 中手动调用Details_Formatsub。 -
我尝试了你的建议。当我尝试将它保存为 PDF 时,我在 report_open 中重置 iLine 所做的更改不会触发。有没有我可以调用的子来确定新一代的打印或导出报告?
标签: ms-access printing vba report