Printing to default and pdf printer simultaneously

davea300

Registered User.
Local time
Today, 14:34
Joined
Mar 16, 2007
Messages
164
I am trying to print a report to the default printer on a client PC and at the same time print the report to a pdf printer and save a copy of it. My code so far (which is is the OnFormat section of the report header) is:

Dim dbs As Database, rst As Recordset
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("tblPrintedReports")
If intPreview >= 0 Then
MsgBox "HP13 Letter Printing"
' Place code here to update a table field to show it was sent to printer
rst.AddNew
rst!ReportName = "rptHP13"
rst!PrintDate = Now
rst!ApplicationNumber = [Reports]![rptHP13].[ApplicationNumber]
rst.Update
[Forms]![frmHL1Main]![subform]![tblPrintedReports].Requery

End If

This prompts the user to select a printer and then saves a date/time when the report was printed. I have no idea how to set the report to print to the default and then to a named pdf printer without prompting the user to select. Also need to save a copy of the letter in a defined location. Any help would be appreciated.
 
Last edited:
Since you already know the exact name of the printers, you need only set the Application.Printer object: (Note that it's always a good idea to put the default printer back when you're done)

Code:
    Dim defaultPrinter  As String
       
   [COLOR="SeaGreen"] 'determine default printer [/COLOR]
    defaultPrinter = Application.Printer.DeviceName
    
    [COLOR="seagreen"]'establish new default[/COLOR]
    Set Application.Printer = Application.Printers("PrinterName")
    
   [COLOR="seagreen"] 'print report using new printer[/COLOR]
    DoCmd.OpenReport reportName, , , , , openArgs
    
   [COLOR="seagreen"] 're-establish the default printer[/COLOR]
    Set Application.Printer = Application.Printers(defaultPrinter)

It takes actually takes some registry manipulation to place the pdf into a particular location, bypassing user interaction. If you aren't comfortable editing the registry, I'd suggest leaving it up to the user.
 

Users who are viewing this thread

Back
Top Bottom