Print Access Report to PDF V6 or V7, using VBA - is this a secret?

T

Tony_VBACoder

I have an Access 2000 application using Acrobat 5, that prints a report to
PDF using VBA code, that works great. I am able to change my printers in my
registry to the Acrobat PDFWriter printer and set the destination PDF file
name, so that there is no interaction with the user as to entering the
filename. This all worked great, until the client upgraded to Acrobat 6 and
7. Now, the "PDFWriter" printer has gone away, and my entire application no
longer works when it comes to the PDF export part.

I have been searching in vain, for the past month, in hopes of finding code
examples of how to print a report to PDF using VBA code. All I keep getting
are links to 3rd Party applications or the Acrobat SDK document. Is this a
big secret in terms of trying to get some sample VBA code from someone who
has actually gotten this to work using VBA along with Acrobat 6 or Acrobat 7,
while NOT using a 3rd Party application? All I need to do is upgrade my
existing code so that it works using the latest versions of Acrobat and I am
having a hard time finding this. My client has Access 2000, not Access 2002,
where I have thought about switching the Printer collection to the new
Acrobat Printer, but under Access 2000, this is not that easy.

I have included my code below that works, using Access 2000 with Acrobat 5.
Can someone please help me out, as I have run into a dead-end.

Thank you.

Public Function PrintToPDF(sReport As String, sFilePathLocation As String,
Optional sCriteria As String) As Boolean
Dim sMyDefPrinter As String, iStep As Integer

' ******* Variables Passed In *************************************
' sReport = The Access Report to export as a PDF file
' sFilePathLocation = The Path and Name of the PDF file to create
' sCriteria = Optional criteria for the report
' *****************************************************************

' This will print a report as a PDF File and save it in a desired location

On Error GoTo Err_RunReport

' Read the current default printer and save the value - we will need this
later when we reset the Default Printer
sMyDefPrinter = dhReadRegistry(HKEY_CURRENT_USER,
"Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device")

' Change the default printer to PDF Writer
If dhWriteRegistry(HKEY_CURRENT_USER, "Software\Microsoft\Windows
NT\CurrentVersion\Windows", "Device", "Acrobat PDFWriter") Then
iStep = 1
' Setting value for PDFFileName in the registry stops file dialog box
from appearing
If dhWriteRegistry(HKEY_CURRENT_USER, "Software\Adobe\Acrobat
PDFWriter", "PDFFileName", sFilePathLocation) Then
' Run the report - First check to see if any criteria is required of
the report
If Not IsMissing(sCriteria) Then
DoCmd.OpenReport sReport, acViewNormal, , sCriteria
Else
DoCmd.OpenReport sReport, acViewNormal
End If
Else
GoTo Err_RunReport
End If
End If

' Restore default printer
dhWriteRegistry HKEY_CURRENT_USER, "Software\Microsoft\Windows
NT\CurrentVersion\Windows", "Device", sMyDefPrinter

PrintToPDF = True

End Function
 
B

Brian

FYI - if you did not already resolve this, you might consider CutePDF as an
alternative. There is a free "print driver only" version that can be
downloaded from www.cutepdf.com (be sure to download & install the free
converter - GhostWriter - also, or it will not work).

The free version of CutePDF is not as powerful as the full version of
Acrobat (does not let you reorder pages, etc), but is a good PDF print
driver. I'm not sure whether it will allow you do the same registry
manipulations.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top