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

Access Report - Save Report to multiple PDF's for each of the vendors 1

Status
Not open for further replies.

lmcate

MIS
Jan 17, 2012
36
US
Hi There,
I have a access report that has multiple vendors and when I run the report I want to save each of the vendors to a PDF file. For example Vendor-A has 2 pages, Vendor-B has 1 page and Vendor-C has 5 pages. Each of the vendor will be saved in a PDf file. Then I would like to email them to me all 3 vendors.

Thanks,

Sam
 
Wouldn't be easier to create a report per Vendor? You can then run 3 reports: one for each Vendor. No need to split them up.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Does that matter? You can program to run all 15 reports with one click of a mouse. Or give user a list to choose from which Vendor(s) to create a report for.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Andrzejek

Do you have a sample A Vba script for this process? Thanks
 
No, I don't. But... how do you process your report right now? Could you show your code? I am sure it would be easy to modify the code to allow creating reports.

I can see the input, something like this:

report_xakuaa.png


---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
If you plan to send the report to all the vendors and don't need to select a specific list of vendors, this can be done by adjusting the where clause in a loop and recordset. I have some code that can save the report to pdf and send the emails with attachments through outlook. If that describes what you are looking for, I can put together some sample code, may not get to it until the weekend though. Another tool you could look into is pdftk (free) which can insert and extract pages from pdf files amongst other things. Though if you used that it is a command line tool and you would need to know which page numbers to extract.
 
Here is the Code that I have so far. I makes one Single PDF



Private Sub timecard_agency_daterange_Click()
On Error GoTo Err_timecard_agency_daterange_Click

Dim stDocName As String
'Save report to local drive
Dim strFile As String
strFile = "W:\Call Center\Call Center Reports\Agency_Reports\" & Format(Now, "YYYYMMDD_hms") & ".pdf"


stDocName = "timecard_agency_daterange_TZ"

DoCmd.OutputTo acOutputReport, stDocName, acFormatPDF, strFile

DoCmd.OpenReport stDocName, acPreview

Exit_timecard_agency_daterange_Click:
Exit Sub

Err_timecard_agency_daterange_Click:
MsgBox Err.Description
Resume Exit_timecard_agency_daterange_Click
End Sub



*****Employer is the key field to separate the PDF's

Thank you in advance.

Sam
 
 https://files.engineering.com/getfile.aspx?folder=504787ef-a410-4c44-819b-42809722ad44&file=Report_PDF.jpg
One step at the time.
You said: "I have 15 vendors", and I assume you have a table with your Vendors:

[pre]
tblVendors
ID Vendor

1 Vendor1
2 Vendor2
3 Vendor3
...
15 Vendor15
[/pre]
So, now I would work on the code to create a PDF report for (any) one Vendor.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
I having problem getting the filter right. The table is Agency_hours and the field is employer. There are 5 employers with employees. The report runs for everyone.

Thanks

Private Sub Label317_Click()
Dim rs As DAO.Recordset
Dim rpt As Access.Report
Dim sFolder As String
Dim sFile As String
Const sReportName = "timecard_agency_daterange_TZ"

On Error GoTo Error_Handler

'The folder in which to save the PDFs
sFolder = "W:\Call Center\Call Center Reports\Agency_Reports\"


'Set rs = db.OpenRecordset("SELECT DISTINCT [Employer] FROM [Agency_Hours]", dbOpenDynaset)
Set rs = CurrentDb.OpenRecordset("SELECT DISTINCT [employer] FROM [Agency_Hours]", dbOpenSnapshot)
With rs
If .RecordCount <> 0 Then 'Make sure we have record to generate PDF with
'Open the Report
DoCmd.OpenReport sReportName, acViewPreview, , , acHidden

'Define a report object so we can manipulate it below
Set rpt = Reports(sReportName).Report
.MoveFirst
Do While Not .EOF
'Build the PDF filename we are going to use to save the PDF with
sFile = Nz(![employer], "") & ".pdf"
sFile = sFolder & sFile
'filter the report to the specific record or criteria we want
rpt.Filter = "[employer]=" & ![employer]
rpt.FilterOn = True
DoEvents 'This is critical or else the filter isn't applied!!!!
'Print it out as a PDF
DoCmd.OutputTo acOutputReport, sReportName, acFormatPDF, sFile, , , , acExportQualityPrint
'If you wanted to create an e-mail and include an individual report, you would do so now
.MoveNext
Loop
'Close the report now that we're done with this criteria
DoCmd.Close acReport, sReportName
End If
End With

'Open the folder housing the PDF files (Optional)
Application.FollowHyperlink sFolder

Error_Handler_Exit:
On Error Resume Next
If Not rpt Is Nothing Then Set rpt = Nothing
If Not rs Is Nothing Then
rs.Close
Set rs = Nothing
End If
Exit Sub

Error_Handler:
If Err.Number <> 2501 Then 'Let's ignore user cancellation of this action!
MsgBox "The following error has occurred" & vbCrLf & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Error Source: Command1_Click" & vbCrLf & _
"Error Description: " & Err.Description & _
Switch(Erl = 0, "", Erl <> 0, vbCrLf & "Line No: " & Erl) _
, vbOKOnly + vbCritical, "An Error has Occurred!"
End If
Resume Error_Handler_Exit
End Sub
 
What happened to Vendors? Or are they the same as Employers?

You have a line of code:[tt]
rpt.Filter = "[employer]=" & ![employer][/tt]
so I assume your report has some kind of Data Source. Do you have a field in this data source named 'employer' ?

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Andrzejek Thank you for your response. The Employer names are reading in the VBA. However, when the report runs the data comes from a query. Also, I believed that query should be used instead of using the table in the database?.
 
If you want to use a query instead of the data from a table, that's fine. It doesn't matter.

But my idea was: create a PDF report for just one Vendor (Employer?).
And after that is accomplish, you can retrieve a list of all of them, loop thru the data, and create a separate PDF for each.

Unless I misunderstand what you want... [ponder]

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Andrzejek Thahk you so much. Do you have a sample of vba that I see?
 
You already do have VBA code to create a PDF report for all Employers (right?), you just need to adjust it to create a PDF for just one Employer.

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Andrzejek, Thank you again. The problem is that I generate a table on the fly with only 5 or 6 vendors. But the report aspect it picks every vendor. I would like to limit with a filter or do loop. do you have a sample?
Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top