Save Report as individual PDF files using a loop?
Hello, I have what seems like a simple scenario for someone who knows how to code but is impossible for me to figure out. :) Thank you in advance for your help!!!
Here's my scenario:
I have a report that creates "Notifications" for numerous customers. The PDF may be 40 pages long for 35 different customers and I have to open the PDF and break out (save individual PDF) for each customer, ending up with 35 PDF files from the 1 PDF report created by Alpha.
Question: Can I create a print loop that saves the 35 reports as individual PDFs with the file names being something like "Notification-CustomerABC.pdf" where "CustomerABC" is pulled from a field within the table?
Here are some more details: the table is named "EFT", the Report is named "Notification" and the customers who need notifications have a value of more than 0 in a field ("Current Balance") located in "EFT" table.
What other questions do you have in order to provide me with the answer to end my manual PDF creating nightmare!?
Re: Save Report as individual PDF files using a loop?
Hi,
I would create a report which is filtered by customers id. You can call the report for each customer where customers balance is > 0.
Code:
dim tbl as p
dim qry as p
tbl = table.open("customers")
qry = tbl.query_create("","Current_balance > 0")
if qry.records_get() = 1 then
while .not. tbl.fetch_eof()
:report.SaveAs("Reportname","PDF","costumer->id = " + tbl.id,"","OutputPDF",.f.)
tbl.fetch_next()
end while
end if
tbl.close()
delete tbl
delete qry
This Code is just copy and past, please adapt to your Needs
Cornelius
Re: Save Report as individual PDF files using a loop?
Thank you for the reply Cornelius! I'm working through adapting it for my needs and have a question about " + tbl.id," part. Do I leave it as that or what do I put in its place?
Re: Save Report as individual PDF files using a loop?
tbl.id is pointing to the matching field in the customers table as in: Tbl.Customer_id or whatever the field is named in that table that matches the field in the report.
Re: Save Report as individual PDF files using a loop?
I do this on a regular basis with employee paysheets and customer invoices.
I had it setup a long time ago using dbfs, but have switched to sql.
In my situation, I have to build the pdfs along the way (combine an unknown number of pages into one pdf)
for each employee/customer.
I'm willing to share if this seems to be something you require.