【问题标题】:MS Access - Trying to set printer before printing, but keeps defaulting to Print to PDFMS Access - 尝试在打印前设置打印机,但始终默认打印为 PDF
【发布时间】:2018-11-30 20:10:37
【问题描述】:

我的客户希望我遍历他的标签打印打印机并找到可用的。

我不在他的办公室,所以只能在没有找到他的情况下将其默认为我的本地打印机。除了,它只在我端打印为 PDF。我什至取消选中“让 Windows 管理您的打印机选择”框。它不断出现pdf。

这是我机器上的打印机列表

0 Send To OneNote 2016
1 PDFill PDF&Image Writer
2 Microsoft XPS Document Writer
3 Microsoft Print to PDF
4 Fax
5 Brother HL-2280DW

我做错了什么?

这是我的代码:

Private Sub cmdPrintWTOutgoingLabels_Click()
Dim LABELprinter As Integer


'check that fields are filled in
If Not IsNumeric(Me.cboOutgoingWT) Then
    MsgBox "Please select a work ticket number first"
    Exit Sub
Else

Dim printerFound As Boolean
Dim numprinters As Integer

printerFound = False
numprinters = Application.Printers.Count - 1


For h = 0 To numprinters


    LABELprinter = Hex(h)


    'if it errors, don't run the code that exits the loop
    On Error GoTo stay_in_loop
    Debug.Print LABELprinter & " " & Application.Printers(h).DeviceName
    If Application.Printer.DeviceName = "ZDesigner GK420d on Ne" & CStr(LABELprinter) & ":" Then

        Set Application.Printer = Application.Printer(h) '"ZDesigner GK420d on Ne" & CStr(LABELprinter) & ":"

        printerFound = True

        Exit For

    End If

stay_in_loop:
Next h
'start error trapping again
On Error GoTo 0
If printerFound = False Then
   Set Application.Printer = Application.Printers(5) 'hard coded to my local printer
            'Sheet5.PrintOut
End If

    DoCmd.OpenReport "WT Outgoing Report", acViewNormal

End If

End Sub

【问题讨论】:

    标签: ms-access printing vba


    【解决方案1】:

    更改某个特定程序的系统默认打印机通常是一种糟糕的用户体验。避免更改Application.Printer!相反,请指定每个报告要使用的打印机,而不是使用默认打印机。

    我使用类似于以下代码的代码将报告打印到特定打印机:

    Dim rptName As String
    rptName = "WT Outgoing Report"
    DoCmd.OpenReport rptName, acViewPreview
    Set Reports(rptName).Printer = Application.Printers(5) 'Or some printer returned by your search code
    DoCmd.SelectObject acReport, rptName
    DoCmd.PrintOut
    DoCmd.Close acReport, rptName
    

    您还可以通过在设计视图中打开报表、进入页面设置、页面,然后在 Printer for MyReportName 下更改打印机来硬编码要打印到的打印机。

    在我的实际应用程序中,我还包含用于更改页面设置和 bin 设置等内容的代码。

    【讨论】:

    • 我以前从来没有搞乱设置打印机,所以尝试转换客户端预先存在的 Excel VBA 代码。现在我知道得更多了。
    猜你喜欢
    • 2011-10-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多