PDA

View Full Version : Print multiple files where filename = recordname



3Dmapper
08-13-2009, 06:13 AM
Hi Iwould like to save my report file as individual pdf's
Where each record contains a unique filename. How to do that?

Oorang
08-14-2009, 08:37 AM
If you have Acrobat installed, just print to "Adobe PDF" printer. It will output as a file.

3Dmapper
08-17-2009, 12:22 AM
Hi Aaron,

I know the function with Acrobat. But this will print my report as one file with 755 pages. I would like to print it as 755 separate pdf files where filename = recordname for each page. I can also split the pdf into 755 separate files in Acrobat but than the filename is like filename1,filename2,filename3 ect.

Peter

DBinPhilly
08-18-2009, 05:34 AM
The way I do this is to output to the standard default location that the pdf writer uses (I don't use Acrobat), then copy the output file to a different location and name it whatever I want to name it.

I have a similar need to yours: I have a construction payroll that I want to divide the input into time sheets by job, even though the data is input by employee. After clean data is achieved, I run through a loop routine that outputs a single job's time sheet, then copy the time sheet as a pdf in a job folder for easy reference by the project managers.

If you would like I could post the code I use to achieve this.

3Dmapper
08-18-2009, 05:54 AM
I would like to have a look at yout code. Thanks.

DBinPhilly
08-18-2009, 07:15 AM
I use two functions residing in the modules objects.

First I make a list of the individual reports I want to print (that is, the job numbers that get individual time sheets) and create a table (PayrollTimesheetControl_T) with a record for each job. I didn't include this code since you can create your own list table based upon whatever criteria you are looking for. I just wanted you to understand what the source table was.

I execute this program from a form that has the appropriate payroll week ending date on it. The final output of the system will be a pdf file that is named something that looks like this:
J:\Acme\10287\OtherDocuments\Timesheet_081609.pdf
where J: = the drive where job information resides
Acme = Customer Name subdirectory
10287 = JobNumber subdirectory
OtherDocuments = subdirectory where timesheets are stored
081609 = week ending date

I excute the program from form named: frmPayrollUpdate
The VBA to execure the module is:
dim iT as Integer
iT = JobTimeSheet(frmWeekEndingDate)

Here is the code that is executed:
______________________________________________________________
Public Function JobTimeSheet(MyDate As Variant)

Dim MyWEDate As String, stOutPath As String, stLinkCriteria As String, stFileName As String

' ----- set up a standard string for the date in mmddyy format
Dim MyD As String, MyM As String, MyY As String
MyD = Day(MyDate)
If Len(MyD) = 1 Then MyD = "0" & MyD
MyM = Month(MyDate)
If Len(MyM) = 1 Then MyM = "0" & MyM
MyY = Year(MyDate)
MyY = Right(MyY, 2)
MyWEDate = MyM & MyD & MyY ' 8/15/2009 becomes 081509

' --- the pdf program (PDF995) requires some time to perform the function so I pause after every print to give it time to complete the print

Dim Start, PauseTime

PauseTime = 4
Forms("frmPayrollUpdate").TimerInterval = 1000

' start at the beginning of the control file and work through one record at a time, printing one report for each record
Dim db As Database, rs As Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("PayrollTimesheetControl_T", dbOpenDynaset)
'start with first record
rs.MoveFirst
rers:
'when done, end it
If rs.EOF Then GoTo Doners

' create the output path
stOutPath = "J:\" & rs!CName & "\" & rs!JobID & "\OtherDocuments\"
stFileName = "Timesheet_" & MyWEDate & ".pdf"

' set criteria to determine which report for which job is printed
stLinkCriteria = "JobID = " & rs!JobID

' identify Access Report Name
stDocName = "PayrollTimesheets_RPDF"

DoCmd.OpenReport stDocName, acNormal, , stLinkCriteria

' allow some time for the report print to occur
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime

Loop

' copy the report to the hard drive using module PDFCopy (Code to follow)
' passing criteria:
' stOutPath = output path
' MyWEDate = Week Ending Date from original form modified to make a usable file name
' C:\PDF995\OUTPUT\PayrollTimesheets_RPDF.PDF = where the normal output of PDF995 writer goes to, along with the file name it is called (in Access that will be the standard report name followed by .pdf
' fill in your own report output path based upon the PDF writer you are using and where it places its output file
' stFileName = created above, the name of the final report as you want it to appear.

iResponse = PDFCopy("Job", stOutPath, MyWEDate, "C:\PDF995\OUTPUT\PayrollTimesheets_RPDF.PDF", stFileName)

' give time for the writing to occur
Start = Timer ' Set start time.
Do While Timer < Start + PauseTime

Loop

' go to next record
rs.MoveNext
GoTo rers

' printing by record is completed
Doners:
rs.Close
Set db = Nothing

End Function
______________________________________________________________

Here is function PDFCopy:
After reading the top instructions, go to TagJob to see the output for the timesheets
______________________________________________________________
Public Function PDFCopy(stApp As String, stOutPath As String, stSubName As String, passit As String, stFileName As String)
'------------------------------------------------------------------------------------------------
' Pass from PDFCopy Command: stAPP = Payroll, Billing
' stOutPath = P:\Payroll\
' -or- P:\Billing\
' -or- J:\CustSort\JobiD
' stSubName - Payroll Only - W/E Date Becomes SubDirectory name
' stFileName - Billing - Job#/Invoice#
' stSubName = Timesheets - W/E Date becomes output file name: "Timesheet_" & MyDate
'
'------------------------------------------------------------------------------------------------
Dim MyPath As String, MyDir As String, MyName As String
Dim stFileOut As String
If stApp = "PAYROLL" Then GoTo tagPR

GoTo NoPr

tagPR:
' MsgBox (stApp & " " & stOutPath & " " & stSubName & " " & Passit & " " & stFileName)
' setup payroll path and file
If IsNull(stSubName) Then
MsgBox ("No Name for W/E SubDirectory")
GoTo NoUpdate
End If
MyDir = stOutPath & stSubName
' MsgBox (MyDir)
' MkDir MyDir
MyPath = MyDir
stFileOut = MyPath & "\" & stFileName
GoTo DonePR

NoPr:
If stApp = "Job" Then GoTo tagJob

'setup billing path and file
stFileOut = "P:\Billing\" & stFileName
GoTo DonePR

tagJob:
stFileOut = stOutPath & stFileName
DonePR:

' copy files to shared drive
FileCopy passit, stFileOut

' delete the file after copying
Kill (passit)

NoUpdate:

End Function