|
切换打印机
Dim rpt As Report
DoCmd.OpenReport ReportName:="rptOrders", View:=acViewDesign, WindowMode:=acHidden
Set rpt = Reports!rptOrders
rpt.Printer = Application.Printers("myPrinterName")
DoCmd.Close acReport, "rptOrders", acSaveYes
Set rpt = Nothing
或
Dim strReport as String
Dim strPrinter as String
Dim rpt as Report
Dim strPrinterName as String
strReport = “MyReport”
strPrinter = “Printer2”
'open report in design view to set printer
DoCmd.OpenReport ReportName:=strReport, View:=acViewDesign, WindowMode:=acHidden
Set rpt = Reports(strReport)
'get the current printer device name
strPrinterName = rpt.printer.DeviceName
Debug.Print strPrinterName
‘change printer
rpt.printer = Application.Printers(strPrinter)
‘get printer name again
strPrinterName = rpt.printer.DeviceName
Debug.Print strPrinterName
'close and save
DoCmd.Close acReport, strReport, acSaveYes
'open report again to see if new printer was saved
DoCmd.OpenReport ReportName:=strReport, View:=acViewDesign, WindowMode:=acHidden
Set rpt = Reports(strReport)
'get the current printer device name
strPrinterName = rpt.printer.DeviceName
Debug.Print strPrinterName
DoCmd.Close acReport, strReport, acSaveNo
=====================
IMMEDIATE WINDOW
Printer1
Printer2
Printer1
或切换打印机
Sub SwitchPrinter()
Dim prt As Printer
' Get current default printer
Set prt = Application.Printer
' Set default printer
Application.Printer = Application.Printers("OtherPrinter")
' Print something, e.g.
DoCmd.PrintOut
' Restore original printer
Set Application.Printer = prt
End Sub
或列出所有打印机
Sub ListPrinters()
Dim prt As Printer
For Each prt In Printers
Debug.Print prt.DeviceName
Next prt
End Sub
|
|