printing into pdf from a report

petko

Registered User.
Local time
Today, 21:16
Joined
Jun 9, 2007
Messages
89
I'd like to print out a report so that each record should be printed into an individual pdf file.
When printing manually, record by record, I use an app called cuteprinter for converting reports into pdf. But that one needs saving path for each individual pdf file. What could I do if I'd like to make a series of record printing? Would there be a way of automatic generating path and file name for each record's print?
Or maybe I should do it completely differently?

Thanks in advance

Peter
 
You can do it like this.
This example is assuming you have a companyID for each of the reports (you would need to figure out what the distinct data to use for your real application) and that one report is to be output for each companyID.
Code:
Function PrintAllSeparate(strFolderPathForOutput As String, strReportName As String) 
   Dim strSQL As String
   Dim rst As DAO.Recordset
   Dim strOutputFile As String
 
   strSQL = "Select CompanyID From TableName Order By CompanyID"
   Set rst = CurrentDb.OpenRecordset(strSQL, dbOpenForwardOnly)
 
Do Until rst.EOF
   strOutputFile = strFolderPathForOutput & rst(0) & ".pdf"
 
   DoCmd.OpenReport strReportName, acViewPreview, WhereCondition:="[CompanyID]=" & rst(0), acHidden
 
   DoCmd.OutputTo acOutputReport, strReportName ,  strOutputFile
 
   DoCmd.Close acReport, strReportName, acSaveNo
 
   rst.MoveNext
Loop
 
rst.Close
Set rst = Nothing
End Function

And then you would call the function by using
Code:
PrintAllSeparate "C:\FolderName\FolderName\", "ReportNameHere"
Make sure to put the backslash (we can code for it too but I didn't want to get too complex yet.
 

Users who are viewing this thread

Back
Top Bottom