View Full Version : Best way to finish this code to export report...


Glowackattack
05-14-2009, 12:37 PM
Hi,
I have the following code used to print a report using Adobe PDF, everything works fine, but i'm not sure how to save the file to a certain directory as a specific filename.

Here is the lowdown of what i am doing, i have to run reports for a number of different clients, i have a control panel where i can select the clients name then a button to print that report using "Adobe PDF" as the printer. The button uses this code:

Private Sub Print_GrossRPT_Button_Click()
On Error GoTo Err_Print_GrossRPT_Button_Click

Dim stDocName As String
Dim Defaultprintername As String
Dim cnt As Integer
Dim a As Integer
Dim AdobeName As Printer
Dim msg As String

'default printername get default printername
Defaultprintername = Application.Printer.DeviceName
'MsgBox (Defaultprintername)

'change it to Adobe PDF

Set AdobeName = Application.Printers("Adobe PDF")

Set Application.Printer = AdobeName

'print the report to PDF

stDocName = "Rpt_GrossPerf"
DoCmd.OpenReport stDocName, acNormal

'Change default printer back to whatever it was

Set Application.Printer = Application.Printers(Defaultprintername)

Exit_Print_GrossRPT_Button_Click:
Exit Sub

Err_Print_GrossRPT_Button_Click:
MsgBox Err.Description
Resume Exit_Print_GrossRPT_Button_Click

End Sub

This code works great and pops up a Save As box to save the report, but the name and location go to my documents as a specific default. Should i use sendkeys to send the location and clients name when that dialog box comes up?? Or is there a way to just save the file to that location then through more code copy the file to a specific location and change the name of the file??

Thanks for any help in advance.

HiTechCoach
05-14-2009, 01:19 PM
Depending on the version of Acrobat, how easy it is to automate the process.

I use this Free Utility (http://www.lebans.com/reporttopdf.htm)

It will allow you to control the location/file name without the user having to do anything or see anything.