访问标签中标签的数量和位置报告当前记录在打印预览中正确但在打印或导出中不正确

Number and position of labels in Access Labels Report on current record correct in Print Preview but not in Print or Export

我尝试从当前记录的子表单创建标签报告。以下是基本潜艇。

表单按钮背后的代码

Private Sub btnBlueLabels_Click()
Dim strWhere As String
Dim strDocName As String
strDocName = "rptBlueLabels"
strWhere = "AllocationAlphaName = """ & Me.frmSubAllocations.Form!AllocationAlphaName & """ AND AdvanceAllocationID = """ & Me.frmSubAllocations.Form!AdvanceAllocationID & """"
If IsNull(Me.frmSubAllocations.Form!AllocationLongName) Then
    MsgBox "No allocation records for this entity. The report will now close."
    Exit Sub
Else
    DoCmd.OpenReport strDocName, acViewPreview, , strWhere, acDialog

End If End Sub

报告背后的代码

 Sub BDetailOnFormat(rpt As Report)
'Print a specified number of blank detail sections.
If intSkipPosition <> 0 Then
        rpt.MoveLayout = True
        rpt.NextRecord = False
        rpt.PrintSection = False
        intSkipPosition = intSkipPosition - 1
    End If End Sub


Sub BDetailOnPrint(rpt As Report)
       If intCopiesCout < intCopies Then
        rpt.NextRecord = False
        intCopiesCout = intCopiesCout + 1

    End If
End Sub

在打印预览中一切看起来都不错。

in the picture: print preview pop up window - three of used labels skipped and three same labels needs to be printed

当我尝试打印打印预览时,它只打印一个标签(不是三个)并且它位于页面的顶部和左侧位置。

Print output

拜托,求教! 谢谢。

将提示输入框设置public变量的代码移动到OpenReport行之前的表单过程中,而不是在报表Open过程中。将模块 headers 中的 3 个变量声明为全局变量,并将可用于表单过程。 (我的偏好是文本框来输入 Skip 和 Copies 值,然后形成代码集全局变量的起始值。使用文本框验证属性。)在表单中进行验证,所以如果输入无效,甚至不要调用报告。实际上,将这段代码放入一个可以被两个按钮调用的 Sub 中。当前按钮中的代码可以合并到此子中。

这可以直接打印到打印机。但是 PrintPreview 到打印机不会,因为报告事件不会再次 运行。这是一种 either/or 情况 - 要么到屏幕要么到打印机,不能两者都做。

无论是屏幕还是打印机,报表记录集都被正确过滤。

其他注意事项:

在几个模块中缺少 Option Explicit

BlueLabels 和 WhiteLabels 模块几乎完全相同。为什么不是 1 个通用模块?它们未显示在导航窗格中。必须创建新模块(合并)并删除旧模块。

WhiteLabels Sub WDetailOnPrint 程序缺少 On Error 语句。

If Then 结构中的 Exit Sub 行不是必需的。 事实上,阻止执行 Exit_Procedure: 代码。 此代码有 Set Warnings True。为什么?永远不会设置错误警告。

RedLabelSecond 文本框显示 'invalid control source' 错误,必须重新选择该字段才能清除。