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
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