Full Version: exporting pdf using different file names
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
Loosh
Hi I have the following code which prints a pdf file of my report based on what county I have selected in my form:

CODE
Private Sub cmdPDFsingle_Click()
    On Error GoTo Err_Handler
    
    Dim strDocName As String
    strDocName = "Directory"

    Dim strCriteria As String
    strCriteria = "[County] = " & Me.lstCounty.Column(0) & ""
    
    Set Application.Printer = Nothing

    Application.Printer = Application.Printers("Adobe PDF")
    
    DoCmd.OpenReport strDocName, acViewNormal, , strCriteria
    
    Set Application.Printer = Nothing


Right now when I click on the command button the "Save As PDF" box pops up and "Directory.pdf" is the default save name. Is there a way where I could make the default save name the County Name followed by "Directory.pdf"

Example: Johnson_Directory.pdf

Thanks
Dragyn
I'm not sure how much control you directly have over the Adobe PDF print driver. I previously was using it, and I handled file naming by letting the PDF Writer save out as a default name, then my code would rename it to my desired filename. A little tedious to code, to be honest.

Now I'm using (and would recommend) Lebans' ReportToPDF code. It gives you a single function call that will take any Report object and output as a PDF.

As an added bonus, it does NOT require any PDF Writing software on the PC to run his code.
cew657
In addition to what Dragyn suggested, I would try:

CODE
strDocName=Me.lstCounty.Column(0) & "_Directory"


HTH

Chad
Loosh
Hi. Thanks for the replies. Chad I tried your code, but it wouldnt work. It needs the actual name of the report in order to open it "Directory". Maybe I could that in some export code?

Dragyn, thanks for pointing that code out to me. I think I'll just stick with the code i'm using it seems to work easily.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.