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

automate save pdf from report

Status
Not open for further replies.

sramey00

Programmer
Jun 9, 2004
149
0
0
US
I have some code to create a pdf from an access report. this works fine, however, i need it to save the file automatically.

here is my code:
Code:
'save default printer information to return to normal when done printing
Set OriginalPrinter = Application.Printer

'set pdf printer
Set Application.Printer = Application.Printers("Adobe PDF")


With rsContacts
Do Until rsContacts.EOF
    strCaseID = rsContacts!CaseID
    strCaseName = rsContacts!CaseName
    strCaseSummary = rsContacts!CaseSummary
    
    'MsgBox strCaseName & " " & strCaseSummary
    
    'Change caption name - caption name is name pdf is saved as
    DoCmd.OpenReport "Cases", acDesign, , "[caseid] = '" & strCaseID & "'" ',  , strCaseID
    Reports![Cases].Caption = strCaseName & ".pdf"
    DoCmd.Save
    DoCmd.Close acReport, "Cases"
    
    'print to pdf writer
    DoCmd.OpenReport "Cases", acViewNormal, , "[caseid] = '" & strCaseID & "'", , strCaseID
    DoCmd.Close acReport, "Cases"
    
    'move to next record
    rsContacts.MoveNext
Loop
End With

Set Application.Printer = OriginalPrinter

when the report is opened (docmd.openreport "cases", acviewnormal.....) i would want to specify the output directory.

can any push me in the right direction?

Thanks!


Mr. Steve

 
Well, I do this now. Go to your main printer folder and open the properties of the Adobe printer. Here you can set it to not prompt fo the file name and I believe on the port tab you can set the directory it prints to. You have to set these things here, they don't stick if you try it on the fly. I generate about 600 individual pdf files every month in on fell swoop, all with different names. You don't need to specify the ".pdf" and you can print directly from code: DoCmd.PrintOut acPrintAll, , , acMedium, 1

If you want to specify individual directories for each one I'm sure that can be done in code also, but I just dump all mine to one and move them later. Hope this helps.
Ken

- If you are flammable and have legs, you are never blocking a fire exit.
Mitch Hedburg
 
yea i found that process in a different forum... which i will repost here later...

i am stuck on creating the folder dynamically based on the name of the file. i think i need a little clarification from management about this issue!

Thanks for your help

Mr. Steve

 
here's the original post i found this process from...

"Instructions below are excerts from one of my specs.
Basically, you tell it where to save and not to ask for a filename.

Click on control panel and select printers. Highlight the printer “Acrobat Distiller” , right click and select properties. Go to the tab “Ports”.

We need to add a port that will act as the default for distiller. This means that we will be able to print via the distiller without having to supply a filename and location. Hence, the vba code will name the file as per its original name with a pdf extension into the folder specified in the port settings. This way we do are not prompted for a filename to saveas.

Click add port and select “PDF Port”.

Select the folder “yourfolder” to act as the default location for documents sent through to distiller via the printer.

Close everything down and select the printer again from the control panel, right click the mouse and select properties.

Click on the button “Printing Preferences”

Select the tab “Adodobe PDF Settings”. Untick everything apart from “Delete log files for successful jobs”. Note that the button we really want to untick is “Prompt for the PDF Filename”. If this is not unticked the vba code will stop running and prompt for a filename and location every time distiller printer is called in the code. "

this is taken from a post. there is other useful information in this thread.




Mr. Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top