Print Page | Close Window

Acess Report set to "Use Specific Report"

Printed From:
Category: PDF reDirect
Forum Name: Programming
Forum Discription: VBA and Batch Tools to control PDF reDirect Pro
Printed Date: 22 Apr 24 at 1:54PM

Topic: Acess Report set to "Use Specific Report"
Posted By: David_Carle
Subject: Acess Report set to "Use Specific Report"
Date Posted: 28 Jun 10 at 4:14PM

I have been investigating a problem that a customer has whereby some Access 2003 reports that previously worked with PDF reDirect now go to the printer instead of PDF Emailing.

In the past I have resolved this by recreating the report, believing there to be some corruption in the report.
However, after doing this today (a tedious process, but it did work), I started thinking about the Printer for [ReportName] option within File - Page Setup - Page tab.
Am I correct in thinking that this option MUST be set to "Default Printer" (rather than "Use Specific Printer") in order to work with PDF reDirect? 
(It would make sense, given the code you supply that saves, sets and resets the default printer).  This would also explain why when I recreate a report from scratch it works OK - because it would be set to Default Printer.
If this is the case, can you suggest a way to save the report setting of a report before changing it to Default Printer (in code), then setting it back after printing to BatchPDF?
The reason for this is that my customer uses many printers (eg different types of stationery) and needs to configure the reports to go to the appropriate printer.
Many thanks for any suggestions.

Posted By: Michel_K17
Date Posted: 29 Jun 10 at 1:04AM

   Please check the VBA code in the Access sample file. There is code in there for setting the default printer for Access 2000, which should not be required for Access 2003. The code shows how I switch the logic for older versions of Access. What you can do is to amend the code to set the default printer as shown for the Access 2000 code.

   Here is the function in the code you should be looking at, and modifying. I hope this helps:

Private Function PrintOutputToBatchPrinter(ByRef MyDocumentName As String, ByRef MyBatchPrinter As String) As Boolean
    Dim oDefaultPrinter As Printer
    Dim DefaultPrinter As String
    On Error GoTo Error_handler
     ' Switch (temporarily) the current Active printer with our Batch Printer
     ' Explanation: Access (2003 and beyond) supports the "ActivePrinter" object,
     ' but older versions of Access (97, 2000) can only print to the "default" printer.
     If Val(Application.Version) >= 11 Then
         ' Access 2003 or 2008
         Set oDefaultPrinter = Application.Printer
         Application.Printer = Application.Printers(MyBatchPrinter)
         ' Older Access version: we need to switch the default printer manually (temporarily).
         ' Note: the driver might be "PDF reDirect v2" or "PDF reDirect Pro" but code below
         '       is most likely to be correct
         DefaultPrinter = GetDefaultPrinter()
         If Not SetDefaultPrinter(MyBatchPrinter & ",PDF reDirect Pro v2,PDF_REDIRECT_PORT:") Then
             ' Could not set the Batch Printer
             oPDF.LastErrorNumber = Err.Number
             oPDF.ErrorLastDLL = Err.LastDllError
             oPDF.LastErrorDescription = "Could not set the Batch Printer as the output printer."
             GoTo Error_handler
         End If
     End If

     ' Create the PDF by sending the Print Job to the Batch Printer
     ' Note: I received a report from someone who was having a problem
     ' printing his Access report. The first few records were being
     ' repeated/duplicated on the second page. Although I did not figure
     ' out why this problem occured, I was able to fix the problem by
     ' generating a "Preview" first before printing. (see below)
     DoCmd.OpenReport MyDocumentName, acViewPreview  ' Generate a Preview First
     DoCmd.OpenReport MyDocumentName, acViewNormal   ' Print the Report
     ' Done. Recover memory
     DoCmd.Close acReport, MyDocumentName
     ' Return the Active Printer to the original one
     If Val(Application.Version) >= 11 Then
         ' Access (2003 and beyond) supports the "ActivePrinter" object
         If Not oDefaultPrinter Is Nothing Then Application.Printer = oDefaultPrinter
         ' Older Access version: Restore the original default printer
         SetDefaultPrinter DefaultPrinter
     End If
    PrintOutputToBatchPrinter = True

End Function

Michel Korwin-Szymanowski
EXP Systems LLC

Posted By: David_Carle
Date Posted: 29 Jun 10 at 2:09AM

Hi Michel

Thanks for your response, but that's not what I'm meaning.

Rather than setting the default printer for Windows, I'm asking about changing the setting for the report (within File - Page Setup - Page tab) between "Default Printer" and "Use Specific Printer" within code.

Or, to put it another way, how would one use PDF reDirect with an Access report that has been set to "Use Specific Printer"?

Posted By: Michel_K17
Date Posted: 29 Jun 10 at 11:33PM

   I really think that it's done via the Application.Printer object.

   From an Application.Report object, you can query the name of the printer (DeviceName), but I do not believe it can be set, and have to use Application.Printer.



Michel Korwin-Szymanowski
EXP Systems LLC

Print Page | Close Window