Print Page | Close Window

Access Reports to Pdf - Bypassing SaveAs

Printed From: www.exp-systems.com
Category: PDF reDirect
Forum Name: Programming
Forum Discription: VBA and Batch Tools to control PDF reDirect Pro
URL: http://www.exp-systems.com/Forum_exp/forum_posts.asp?TID=203
Printed Date: 22 Nov 24 at 6:04PM


Topic: Access Reports to Pdf - Bypassing SaveAs
Posted By: Spyryl
Subject: Access Reports to Pdf - Bypassing SaveAs
Date Posted: 16 Apr 06 at 11:33AM
I have tried the code that you supplied for the conversion of Access reports into pdf's. And while it seemed to have worked for everyone else, I couldn't quite get it to do what I needed.

Is it true that the batch printer dictates where files are to be saved, and if so am I able to create/delete batch printers at runtime.

Also is it possible to print out from Access without the SaveAs Dialog appearing (I am using the pro version).

And when placing database onto anothers computer in order for the code to contiue working do they also need to purchase the pro version of redirect or is there a runtime control that can be sent with it???

Thanks for the help...



Replies:
Posted By: Michel_K17
Date Posted: 17 Apr 06 at 12:44AM
Hi,

   Just answered your other post. You could create/delete batch printers at run time if you really wanted to. There is, however, a 5 second pause while Windows 2000/XP does it's "magic" now that they have all the security code which was not there in Win 9X / Win NT.

   However, once you have just one batch printer, you can dictate the location of the PDF programmatically by changing a setting for that batch printer, so installing a new batch printer is really not necessary. See the sample VB class code: try it in Excel or Word first, than move the code into Access (plus the additional code posted on the forum in the other post). It's pretty straightforward, but let me know if you need help.

   Yes, it is possible to bypass the "Save As" dialog as long as you use the batch printer. In fact, if you look at the code in the VB class (it is not protected), you can see that you can change a whole bunch of settings beyond just the directory/filename.

   Placing the database on somebody else's computer will technically require that other person to purchase PDF reDirect Pro, install it, and install a batch printer.

   Cheers!

Michel.


Posted By: Spyryl
Date Posted: 17 Apr 06 at 11:04AM
Almost got it to work. The only thing wrong was that it isn't saving the report as the file I have designated.
I don't seem to be able to programmatically change the settings for the Batch printer.
Would you mind having a look at the code and seeing if you can spot where I'm going wrong..

Function TestPrinters()
Dim oPDF As New clsPrint_PDF_Pro
Dim otmpPrinter As Printer

On Error GoTo Err

Set otmpPrinter = Application.Printer
Application.Printer = Application.Printers("Batch PDF - VBA")

If oPDF.SetOutput("Batch PDF - VBA", "C:\Test This", "Access_Report.pdf") = 1 Then _
   DoCmd.OpenReport "rptSendout", , , "ClientID=" & 1

MyExit:
   If Not otmpPrinter Is Nothing Then Application.Printer = otmpPrinter
   Exit Function

Err:
   'ShowMyErr Err.Number & vbCrLf & Err.Description, 16
   MsgBox Err.Number & vbCrLf & Err.Description, 16
   Resume MyExit

End Function

Thanks again for the help


Posted By: Michel_K17
Date Posted: 17 Apr 06 at 11:16PM
Hi,

   I took your code and made a couple of minor modifications, and it seems to be working for me. Here is my code (I have, in the comments, Identified all the changes that I made to your code as well as a couple of questions to ask yourself.



Originally posted by Here is the Modified Code

Function TestPrinters()
Dim oPDF As New clsPrint_PDF_Pro
Dim otmpPrinter As Printer
' I added this variable to record any errors from the vbClass

Dim rtn As Long

On Error GoTo Err

Set otmpPrinter = Application.Printer
Application.Printer = Application.Printers("Batch PDF - VBA")

' Try setting up the batch printer
' Note: Do you have a batch printer called "Batch PDF - VBA" setup?

rtn = oPDF.SetOutput("Batch PDF - VBA", "C:\Temp", "Access_Report.pdf")

' Check for success

If rtn = 1 Then
   DoCmd.OpenReport "rptSendout", , , "ClientID=" & 1
Else
    MsgBox "Batch Printer path setup failed with Error =" & Str$(rtn)
End If

MyExit:
   If Not otmpPrinter Is Nothing Then Application.Printer = otmpPrinter
   Exit Function

Err:
   'ShowMyErr Err.Number & vbCrLf & Err.Description, 16

   MsgBox Err.Number & vbCrLf & Err.Description, 16
   Resume MyExit

End Function


Here are the error codes you might get if setting up the batch printer fails

    ' This function returns an error code as follows:
    ' 0 = UNKNOWN_ERROR
    ' 1 = SUCCESS
    
    ' PRINTER ERRORS
    ' 100 = PRINTER_NOT_FOUND
    ' 101 = COULD_NOT_ENUMERATE_PRINTERS
    ' 102 = COULD_NOT_OPEN_PRINTER
    ' 103 = COULD_NOT_SET_PRINTER_SETTINGS
    ' 104 = PRINTER_NOT_BATCH_PDF_PRINTER
    
    ' PATH ERRORS
    ' 105 = PATH_IS_NOT_VALID
    ' 106 = PATH_IS_EMPTY
    ' 107 = PATH_IS_GREATER_THAN_255_CHARACTERS
    
    ' FILENAME ERRORS
    ' 108 = FILENAME_IS_EMPTY
    ' 109 = FILENAME_IS_GREATER_THAN_200_CHARACTERS


Posted By: Michel_K17
Date Posted: 17 Apr 06 at 11:23PM
Hi

   If you get the previous code working..

   You asked about any additional settings that you can change in the Batch Printer. Most of the settings are accessible via the Batch Printer Preferences screen in the main program. However, if you want to change them programmatically, open the "clsPrint_PDF_Pro" that you added to your database code, and look for this section of code. That's the code that you can modify to set different settings.

Originally posted by How to Change Settings

            ' Get the settings for this batch printer (if there)
            With MyBatch
               ' ini file exists - load it.
               Open UserAppData & BATCH_PATH & Temp For Input As #1
               Input #1, .Printer              ' Name of the Batch Printer
               Input #1, .Path                 ' Path to Output PDF to
               Input #1, .FileName             ' Filename of the PDF
               Input #1, .Show_Progress        ' Show Progress Bar (?)
               Input #1, .Overwrite            ' 0 = no warning, 1 = warn, 2 = new file + number, 3 = append, 4 = prepend
               Input #1, .Trailer_Digits       ' Format of trailing digits (3 = 3 zeros = "000")
               Input #1, .Number_Start        ' Default sequence start number
               Input #1, .Settings             ' GS Conversion Settings
               Input #1, .FileType             ' 0 = PDF, 1 = Encrypted PDF
               Input #1, .User_Password        ' User Password
               Input #1, .Locked               ' PDF is restricted
               Input #1, .Lock_Permissions     ' PDF Permission Options(see iSED QuickPDF docs)
               Input #1, .Lock_Password        ' AKA Master Password
               Close #1
              
               ' Update the settings
               .Path = sPath
               .FileName = sFilename
              
               ' ADD YOUR SETTINGS CODE HERE

               ' Save the updated settings
               Open UserAppData & BATCH_PATH & Temp For Output As #1
               Write #1, .Printer              ' Name of the Batch Printer
               Write #1, .Path                 ' Path to Output PDF to
               Write #1, .FileName             ' Filename of the PDF
               Write #1, .Show_Progress        ' Show Progress Bar (?)
               Write #1, .Overwrite            ' 0 = no warning, 1 = warn, 2 = new file + number, 3 = append, 4 = prepend
               Write #1, .Trailer_Digits       ' Format of trailing digits (3 = 3 zeros = "000")
               Write #1, .Number_Start        ' Default sequence start number
               Write #1, .Settings             ' GS Conversion Settings
               Write #1, .FileType             ' 0 = PDF, 1 = Encrypted PDF
               Write #1, .User_Password        ' User Password
               Write #1, .Locked               ' PDF is restricted
               Write #1, .Lock_Permissions     ' PDF Permission Options(see iSED QuickPDF docs)
               Write #1, .Lock_Password        ' AKA Master Password
               Close #1


   I hope that helps!

Michel

P.S. Here is the screen shot of where you change the batch printer settings manually in the program (accessible via the "Preferences" button in PDF reDirect Pro.


Posted By: Spyryl
Date Posted: 18 Apr 06 at 11:01AM
I don't seem to have the above bit of code in my copy of the class module that I imported.

I have the top code (with the errors), but not the bottom code (with the write #1 and Input #1)


Posted By: Michel_K17
Date Posted: 19 Apr 06 at 1:42AM
Hi,

   I'm guessing that you are running the older v2.0 VB class. You need to run the VB class for the new v2.1 (which also explains why the report name is not working).

   The new VB class is available [ http://exp-systems.com/PDFreDirect/Download/PDF_Class4VB_Rev_D.zip - here ].

   Cheers!

Michel


Posted By: Spyryl
Date Posted: 19 Apr 06 at 1:57AM
Thats it.

You are a genuis.

I hope the code I sent you was also useful to you.

Many Thanks

C!!!


Posted By: Michel_K17
Date Posted: 19 Apr 06 at 1:31PM
Cool!



Print Page | Close Window