【问题标题】:DoCmd.PrintOut does only Print one copyDoCmd.PrintOut 只打印一份
【发布时间】:2018-04-29 04:50:29
【问题描述】:

我看到有一个similar question 是我的,但是给出的解决方法对我来说是不可能的。 我必须打印多达 1000 个或更多。

 DoCmd.OpenReport Report, acViewReport 'Open report
 DoCmd.PrintOut , , , acHigh, copys' Print report

(作为副本我已经指定了副本的数量。)

我是不是做错了什么?

还有其他方法可以打印报告吗?

感谢您的帮助。

完整代码:

Private Sub cmd_openreport_Click()

'Set Variables
Dim Report
Dim Etikette
Dim Copyes As String
Dim SQLString
Dim SQLString2


DoCmd.SetWarnings False 'Turns Off Warnings

Etikette = comb_etiketten_auswahl 'Etikette Equals the             comb_etiketten_auswahl value
Report = comb_etiketten_layout 'Report equals the value in the dropdown list
Copyes = Forms!frm_Hauptmenu!comb_etiketten_auswahl.Column(1)


'If The Etiketten Dropdown is empty message to client
If Etikette <> "" Then

'Do Nothing/Continue

Else
MsgBox "Bitte wählen Sie einen Datensatz aus"
Exit Sub

End If


'If The Report Dropdown is empty message to client
If Report <> "" Then

'Do Nothing (because dropdown is mot empty)

Else
MsgBox "Bitte wählen Sie ein Etikettenlayout aus"
Exit Sub

End If

MsgBox anzahl
'If Amount of copies is less than 1 message to client
If anzahl > 0 Then


On Error GoTo Error_MayCauseAnError
    DoCmd.OpenReport Report, acViewReport 'Open report
    DoCmd.PrintOut , , , , Copyes
    DoCmd.Close Report ' Close the Report

编辑:

这个问题无关紧要,没有目的了! 这是一个内部脚本错误!

【问题讨论】:

  • 请说明为什么您无法使用该解决方法。打印数量无关紧要。
  • 试试这个example DoCMD.PrintOut From:=2, To:=3, Copies:=3
  • 那行不通@nishitdey :(
  • 那我够不着:(。对不起。你去MSDN链接了吗
  • 是的,我去过那里,但没有找到任何有用的东西...感谢您的帮助

标签: vba ms-access


【解决方案1】:

您是否将 copyes 声明为 Variant?

阅读PrintOut文档,发现如下:

姓名份数

必需/可选可选

数据类型变体

说明要打印的份数。如果将此参数留空,则假定为默认值 (1)。

https://msdn.microsoft.com/en-us/vba/access-vba/articles/docmd-printout-method-access

另外,请尝试使用值而不是仅用于测试的变量。


当你使用函数时,阅读函数文档非常重要,了解这个函数(或过程)需要什么样的变量。 在这种情况下,这个函数使用了一个Variant 变量(不知道为什么),那么你应该提供一个Variant 对象。 举个例子吧。

你有一台饮料机。 让我们从变体的角度来考虑金钱。 papermetal。 您的饮料机只接受paper 作为金钱。如果你尝试插入metal(硬币),你的机器会报错。 在这种情况下,您需要提供您的饮料机接受的具体金额。

希望这些说明能让您更好地理解问题,并帮助您阅读您正在使用的函数或过程的文档。

【讨论】:

  • 是的,copys 是一个变量,如果我只输入 12,它的作用是一样的(这个变量在我用 msgbox 检查的时候都是正确的)
  • 我的意思是...copys 变量类型是Variant?
  • Dim Copyes As String 应该是Dim Copyes As Variant
  • 哦,好吧,我会试试的。有什么区别?只是为了让我理解代码;-)
  • 嘿@David G. 感谢您对现在适用于 100 份副本的变体的帮助,但是当我关闭报告时最后出现错误......不知道为什么...... . 有什么想法吗?
【解决方案2】:

我想我不明白为什么您在“PrintOut”之后有“Copies”。您想要的只是打印一定数量的副本,对吗?你可以简单地把

DoCmd.PrintOut , , , , copys 'Print report

或者,你也应该能够只写

DoCmd.PrintOut Copies:=copys 'Print report

你不需要写 acHigh 因为这是默认值

【讨论】:

  • 感谢遮阳篷。对不起,但我不得不纠正我的问题。我使用了您的第一个选项...但那是行不通的...它只打印一个副本...
  • 我认为您应该向我们展示更多代码,以便我们可以看到您在哪里声明副本并更新其值
  • 您是否尝试过 David 建议的“Dim Copyes As Variant”?
猜你喜欢
  • 2011-05-17
  • 2017-12-25
  • 2011-08-15
  • 1970-01-01
  • 1970-01-01
  • 2019-03-31
  • 1970-01-01
  • 2011-06-04
  • 2014-03-16
相关资源
最近更新 更多