Suggestions Needed: Printing PDFs Using Acrobat 8

E

egun

I have looked all over (here, Google, Adobe), but have not been able to find
the right info for printing (saving) PDF files from Access using Adobe
Acrobat. I have a button on one of my forms that prints a report, based on
the current record, to a PDF file. That part works. What I can't get it to
do is save the PDF file in a pre-determined location using a pre-defined
name. I want to include that ability in the VBA. Right now I still get the
"Save As" dialog box with the "ReportName.pdf" as the default name, and the
default directory set to whatever the Adobe PDF printer setting is.

I am using something I found through Google, but it doesn't seem to work
correctly for my setup (Access 2003 SP2 and Adobe Acrobat 8 Standard). If
anyone has any suggestions for getting Access and Acrobat to communicate the
way I want them to, please respond.

The VBA I am currently using (found at Planet Source Code):

Public Function RunReportAsPDF(rptName As String, sPDFPath As String,
sPDFName As String)
'---------------------------------
' rptName = Microsoft Access report name you want to create pdf from
' sPDFPath = the directory path where you want to create the pdf file (ex. -
"c:\data\")
' sPDFName = the name of the pdf file you are wanting to create (ex. -
"file001.pdf")
'---------------------------------
Dim sMyDefPrinter As String
On Error GoTo Err_RunReport

'Save current default printer
sMyDefPrinter = bGetRegValue(HKEY_CURRENT_USER, "Software\Microsoft\WIndows
NT\CurrentVersion\Windows", "Device")
' Set default printer to PDF Writer
bSetRegValue HKEY_CURRENT_USER, "Software\Microsoft\Windows
NT\CurrentVersion\Windows", "Device", "Adobe PDF"
' Setting value for PDFFileName in the registry stops file dialog box from
appearing
bSetRegValue HKEY_CURRENT_USER, "Software\Adobe\Adobe PDF", "PDFFileName",
sPDFPath + sPDFName
' Run the report
DoCmd.OpenReport rptName, acViewNormal
Exit_RunReport:
' Restore default printer
bSetRegValue HKEY_CURRENT_USER, "Software\Microsoft\WIndows
NT\CurrentVersion\Windows", _
"Device", sMyDefPrinter
Exit Function
Err_RunReport:
MsgBox Err.Description
Resume Exit_RunReport
End Function

Thanks,

Eric
 
A

Albert D. Kallal

You'll find the code to create the pdf here:

http://www.lebans.com/reporttopdf.htm


The advantage of the above solution is several fold, first of all you don't
have to install a pdf writer system on the computer, furthermore you don't
have to switch printers because the above does not install and use a printer
to create a PDF. Furthermore the aobove system also allows you to specify
the output pdf file name you wish to create.

The above also elimonates the issues of having to install and purchase a pdf
system. (the above is also completely free ).

So the above will solve your problem of specifying the output file name, and
furthermore means that you don't have to have a particular version of Adobe
installed on your computer.
 
E

egun

Albert,

Thank you for the reply. Unfortunately I live and work in a corporate
environment and it is very difficult to bring in third party software such as
Mr. Labans' excellent work. I am tied to Adobe Acrobat because that is the
corporate package of choice. So I must search for a solution using that
package.

Regards,

Eric
 

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