Reports inside a loop

I have already found the solution to my problem, but I don’t understand why my original code doesn’t work. On page 143 (Posted Sales Invoices), I would like to create a PDF of all sales invoices that are selected by the user. The below code does not work however the code below that does work. Can someone please explain to me why?

Code that doesn’t work

…(get the page selection etc and put into pSalesInvoice)…

REPEAT

REPORT.SAVEASPDF(ReportNo,FileName,pSalesInvoice);

//will only create the first record multiple times, however pSalesInvoice is correctly looping through the records

UNTIL pSalesInvoice.NEXT = 0;

However, the below code does work

…(get the page selection etc and put into pSalesInvoice)…

REPEAT

SETRANGE(“No.”,pSalesInvoice.“No.”);

REPORT.SAVEASPDF(ReportNo,FileName,Rec);

SETRANGE(“No.”);

//will create the PDF files exactly as it should*…*

UNTIL pSalesInvoice.NEXT = 0;

Any ideas would be greatly appreciated.

Alex

Presume you have included in the first non working version before the first repeat something like:

CurrForm.SETSELECTIONFILTER(pSalesInvoice);
IF pSalesInvoice.findfirst then

Neil

Thanks for your reply Neil, but that is exactly as the code already read.

It seems to me before a report is called a SETRANGE has to be done to the record before sending it to the report. Not really sure why. (That is a GET by itself doesn’t seem to work nor does a FINDFIRST/FINDSET and scrolling through them.)

Alex

Thought you would have. So not sure why it is not working. Is pSalesInvoice a local or global?

Neil

When you execute a report with SAVEASPDF, then it’s just as if you execute it with a RUN. If you run it with the record variable, then it will run using the filters applied to the record variable. With no filters, then it would basically save/print all invoices. That is presuming your invoice report is or works similar to the standard invoice.