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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

default print path when creating a PDF file through VB

Status
Not open for further replies.

OlafBogus

Programmer
Oct 1, 2002
77
0
0
GB
I need info on how to change the default print path when creating a PDF file through VB. I set the current printer to the PDF printer and then treat it as a standard printer but it always opens a file box with the windows path as the default save path but I need to change it to a network path automatically.
 
VB or VBA? Must be VB, I wouldn't know how to do it in VBA.

There must be a VB forum round here somewhere ...

 
Hi Olaf,

This is a known issue with creating pdfs (from VB or VBA). The solution is either to muck about in the registry or to use SendKeys to control the dialog box.
Have a look at the info behind this link:
might be useful

I've also got a tool set up in Excel which creates pdfs automatically (i.e. bypassing the dialog box) from reports created in Excel. If you'd like a look at the code, let me know



Cheers
Nikki
[bat] Look, mommy, I'm flying!
 
Hi Nikki,

I know your last post is a few months old. Just in case you see this message, could I take a look at the code you mentioned? ("I've also got a tool set up in Excel which creates pdfs automatically (i.e. bypassing the dialog box) from reports created in Excel. If you'd like a look at the code, let me know")

Trying to do the same thing now... even the SENDKEYS isn't working to get past the dialog box.

Thanks in advance.
Greg
 
This post is from a previous reply from Tek_tips ....

The following code will output an Access report as a PDF file. (you can modify to use with excel)

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