CompanyInfo.GET(); PaymentList.SETRANGE(Posting_Date, StartDate); IF NOT PaymentList.OPEN THEN EXIT; WHILE PaymentList.READ DO BEGIN Body := ''; EmailTo := email address here; EmailCC := 'email address here'; Subject := 'Test Email'; Mail.AddBodyline(STRSUBSTNO('<table><tr><td>%1</td></tr></table>', PaymentList.Name)); Mail.AddBodyline('Dear Customer,'); Mail.AddBodyline('<br><br>'); Mail.AddBodyline('The below payment has been received:'); Mail.AddBodyline('<table cellpadding="5" cellspacing="5"><tr><th>Posting Date</th><th>Amount</th></tr>'); Mail.AddBodyline(STRSUBSTNO('<tr><td>%1</td><td>$%2</td></tr>', PaymentList.Posting_Date, FORMAT(PaymentList.Amount, 0, '<Precision,2:2><Standard Format,0>'))); Mail.AddBodyline('</table>'); InvoiceList.SETFILTER(Document_No, PaymentList.Document_No); InvoiceList.SETFILTER(Vendor_No, PaymentList.Vendor_No); IF NOT InvoiceList.OPEN THEN EXIT; Mail.AddBodyline('This payment was applied to the below invoice(s):'); Mail.AddBodyline('<table cellspacing="5" cellpadding="5"><tr><th>Posting Date</th><th>Amount</th></tr>'); WHILE InvoiceList.READ DO BEGIN Mail.AddBodyline(STRSUBSTNO('<tr><td>%1</td><td>$%2</td></tr>', InvoiceList.Posting_Date, FORMAT(InvoiceList.Amount, 0, '<Precision,2:2><Standard Format,0>'))); END; Mail.AddBodyline('</table>'); InvoiceList.CLOSE; Mail.AddBodyline('<br>'); Mail.AddBodyline('Regards,'); Mail.AddBodyline('<br><br>'); Mail.AddBodyline(CompanyInfo.Name); Mail.NewMessage(EmailTo,EmailCC,Subject,Body,'',FALSE); CLEARALL; END; PaymentList.CLOSE;
Answers
apparently, your CLEARALL, in combination with the WHILE ...READ loop, doesn't do the job.
So you have to consider other options:
- program a REPEAT..UNTIL and use CLEAR(Mail);
- create and call a function everytime you read a new rocord, programm the mail-functionality there, and create the variable Mail as a local variable
Ernst
\:D/