如何为整个工作选择打印机? [英] How to select a printer for entire job?

查看:82
本文介绍了如何为整个工作选择打印机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个Access 2003数据库,该数据库具有一个表格,可以根据用户选择的工作来打印一系列报告.该查询也位于VBA代码中,该代码将查看作业的分类零件并打开其相应的报告.

I currently have an Access 2003 database, which has a form to print a series of reports based off what job the user selects. The query is within the VBA code as well, which looks at the job's cataloged parts and opens their corresponding reports.

以下是正确执行此操作的代码:

Here's the code that does so, correctly:

Private Sub Print_Report_Click()

Dim default_cat As Dao.Database
Dim d As Dao.Recordset
Dim q As String


Set default_cat = CurrentDb
q = "SELECT DISTINCT CATALOG, USER3 FROM [_MASTER_UPLOAD] WHERE SerialNumber='" & Me.[SerialNumberSelection] & "'"
Set d = default_cat.OpenRecordset(q, dbOpenDynaset)
d.MoveFirst

DoCmd.RunCommand acCmdPrint

Do While Not d.EOF


Select Case d!USER3

  Case "COM"
     DoCmd.OpenReport "RPTCompressor", , , "CATALOG = '" & d!CATALOG & "'"

  Case "CON"
     DoCmd.OpenReport "RPTCondenser", , , "CATALOG = '" & d!CATALOG & "'"

  Case "CRV"
     DoCmd.OpenReport "RPTCapacityRegValve", , , "CATALOG = '" & d!CATALOG & "'"

  Case "CV"
     DoCmd.OpenReport "RPTCheckValve", , , "CATALOG = '" & d!CATALOG & "'"

  Case "etc..."

End Select

d.MoveNext

Loop

d.Close

End Sub

基本上,现在我的问题所在是打印机选择DoCmd.RunCommand acCmdPrint.出现弹出窗口,我可以选择我想要的任何打印机,但是该选择似乎只会影响该组的第一份报告(所有其他报告都进入计算机的默认打印机).我很可能会从我们的打印室打印机中打印出报告,或者仅将它们转换为PDF,但这也意味着我无法对其进行硬编码以始终将其打印到特定位置.

Basically now where my problem lies is in the printer selection DoCmd.RunCommand acCmdPrint. The popup appears and I can select whatever printer I want, however that selection only seems to effect the first report of the group (all the others go to the computer's default printer). Most likely, I'll print the reports out from our print room printer, or just convert them to PDFs, but this also means I can't hardcode it to always print to a specific location.

如何使我的打印机选择对所有报告保持有效,最好不必为同一组中的每个报告运行acCmdPrint命令?

谢谢.

编辑

此问题已在此处指定并继续:如何将引用传递给组合框?

This question is specified and continued here: How to pass reference to combobox?

推荐答案

从对如果您的报告设置为在默认打印机上打印,最简单的方法是临时更改默认打印机:

The easiest way, if your reports are set to print on the default printer, is to temporarily change the default printer:

Set Application.Printer = Application.Printers("myPrinterDeviceName")
DoCmd.OpenReport "FirstReport"
DoCmd.OpenReport "SecondReport"
' ...
Set Application.Printer = Nothing

如果没有,则可以按报告执行:

If not, you can do it per report:

DoCmd.OpenReport "FirstReport", View:=acPreview, WindowMode:=acHidden
Set Reports("FirstReport").Printer = Application.Printers("myPrinterDeviceName")
DoCmd.OpenReport "FirstReport", View:=acViewNormal

链接的页面上还有一个示例,说明如何显示可用打印机列表以供选择.

The linked page also has an example on how to present a list of available printers for selecting one.

Private Sub GetPrinterList(ctl As Control)
    Dim prt As Printer
    For Each prt In Printers
        ctl.AddItem prt.DeviceName
    Next prt
    ctl = Application.Printer.DeviceName
End Sub

这篇关于如何为整个工作选择打印机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆