Question : How to print a MS Access report to multiple network printers

I have an ms access report and am using MS access 2007.  How do I print a report to multiply network workprinters either with a macro or VBA code.  would the code similar below work?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
'example
On Error GoTo Err_Command418_Click
 
 
    Dim stDocName As String
    Dim strDefaultPrinter as string
 
  stDocName = "rptCustomerList"
 
' get current default printer.
   strDefaultPrinter = Application.Printer.DeviceName
 
' switch to printer of your choice:
    Set Application.Printer = Application.Printers("HP LaserJet Series II")
 
'Print Report
  
    DoCmd.OpenReport stDocName, acprintpreview
 
 
' switch to printer of your choice:
    Set Application.Printer = Application.Printers("HP OfficeJet 7500")
 
'Print Report
    stDocName = "rptCustomerList"
    DoCmd.OpenReport stDocName, acprintpreview
 
'Swtich back.
 
Set Application.Printer = Application.Printers(strDefaultPrinter)
 
Exit_Command418_Click:
    Exit Sub
 
Err_Command418_Click:
    MsgBox err.Description
    Resume Exit_Command418_Click

Answer : How to print a MS Access report to multiple network printers

Interesting question.

You need to be careful here, Reports are closely linked to the respective printer they are associated with.
So the resulting "Print" command may throw an error, or the actual printout may not print correctly.

See here for some great info.
http://msdn.microsoft.com/en-us/library/ee336132.aspx

My guess is that you can loop the printer collection.
On each loop (printer) you can set it as the default and print the report

I am not near a network setup right now, but here is some rough, untested code:

Dim p As Printer
Dim strReportName As String
strReportName = "YourReportNameHere"

For Each p In Printers
  DoCmd.OpenReport strReportName, View:=acPreview, WindowMode:=acHidden
  Set Reports(strReportName).Printer = p.DeviceName
  DoCmd.OpenReport strReportName, View:=acViewNormal
  DoCmd.Close acReport, strReportName, acSaveNo
Next p

Perhaps you can modify it to work in your setup.

Anyway, I am sure you see the logic behind this approach.

;-)

JeffCoachman
Random Solutions  
 
programming4us programming4us