Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a PDF w/ PDFWriter without SaveAs Dialog 1

Status
Not open for further replies.

rpthomas

Programmer
Feb 2, 2002
7
US
Is there a way to print to PDFWriter using Visual Basic and not have the File SaveAs Dialog appear. I've tried creating a Word Object and using the syntax;

Word.ActivePrinter = "Adobe PDFWriter"

Word.Application.Printout . . . . OutputFileName:="C"\temp\filename.doc"

but the resulting PDF file is empty.

Any suggestions?
 
I saw this solution on this site,...I don't remember who posted it though,....
'****************************************
The following code will output an Access report as a PDF file.

You’ll need:
- the Acrobat PDFWriter software on your machine.
- Your own version of the Get/Save registry setting calls below

Note: this is a chopped down version of my real code just to show the salient points. You’ll need to adapt this to your own context.

Public Sub RunReportAsPDF
On Error GoTo Err_RunReport

‘ Folder where PDF file will be written
sPDFPath = “C:\myapp\archive\”

‘ Save current default printer
sMyDefPrinter = GetRegistryString(HKEY_CURRENT_USER, "Software\Microsoft\WIndows NT\CurrentVersion\Windows", "Device")
‘ Set default printer to PDF Writer
SaveRegistryString HKEY_CURRENT_USER, "Software\Microsoft\WIndows NT\CurrentVersion\Windows", "Device", "Acrobat PDFWriter"

sPDFName = “myReport.pdf"
‘ Setting value for PDFFileName in the registry stops file dialog box from appearing
SaveRegistryString HKEY_CURRENT_USER, "Software\Adobe\Acrobat PDFWriter", "PDFFileName", sPDFPath + sPDFName

‘ Run the report
DoCmd.OpenReport “myReport”, acPreview

Exit_RunReport:
' Restore default printer
SaveRegistryString HKEY_CURRENT_USER, "Software\Microsoft\WIndows NT\CurrentVersion\Windows", "Device", sMyDefPrinter
Exit Sub

Err_RunReport:
MsgBox Err.Description
Resume Exit_RunReport

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top