On Codeunit 82, I call another Codeunit with this code. The problem is that, it is the next-latest invoice which is attatched the mail.
This is only test, a real solution needs more code. BUT all is working exept the "attatch-problem".
..:
OnRun(VAR Rec : Record "Sales Invoice Header")
// Print to PDF file and generate the right invoice !!
REPORT.RUN(50206,FALSE,FALSE,Rec);
AttatchedFileName := 'c:\faktura.pdf';
Text_Subject := 'Faktura no. '+Rec."No.";
Text_Body := 'Due date : '+FORMAT(Rec."Due Date");
// NewMessage(
'info@rainerbay.dk','info@rainerbay.dk',Text_Subject,Text_Body,AttatchedFileName,TRUE);
::.
// Where "NewMessage" is a procedure in the Codeunit.
Comments
Try doing this before creating the file:
if exists(filename) then
erase(filename)
the other thing to watch for is that you give the OS time to save the attachment - try doing a repeat until with a sleep command (and maybe a yield to give the OS chance to do its stuff) until the file exists.
the problem is the REPORT.RUN
If you do not use RUNMODAL the code will continue to run while the report is generated. So when the "New Message" code is run the report is not finished yet.
If you use REPORT.RUNMODAL the system will wait for a reponse to the print before it continues.
br
Anders
I guess its while I still use the free pdf995 with PopUps.. I put in a little "wait" in the code..and wupty it works.
Thanks alot..
E-mail: info@rainerbay.dk
Skype: rainerbaydk
http://www.BiloBeauty.com
http://www.autismspeaks.org