Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Saving as Excel File with filter

Posted on by 5,124

I had this method working whereby I am sending a specific report as a PDF attachment to an email I am sending.  However, I had a request from our user that asked for Excel version instead.  So I thought it's no biggy.  Rather that sending 'SAVEASPDF', I just changed it to 'SAVEASEXCEL'.  Note that prior to sending the report as pdf/excel, I am filtering the source data (need to filter the document date).  I do this using recordref and fieldref.  Like I said, everything worked when sending report as PDF.  See below code snippet:
OpenOrderRangeFile := TempFilename + 'OrderingReport_'+FORMAT(StartDate,0,'<Month,2>_<Day,2>_<Year4>')+'_'+FORMAT(EndDate,0,'<Month,2>_<Day,2>_<Year4>')+'.xls' ;
FieldRefVar := RecRef.FIELD(99);  //Document Date
FieldRefVar.SETRANGE(StartDate,EndDate);

IF RecRef.COUNT > 0 THEN
    BEGIN
        bAttached := TRUE;
        VarRecRef := RecRef;
        //REPORT.SAVEASPDF(50097,OpenOrderRangeFile,VarRecRef);
        REPORT.SAVEASEXCEL(50097,OpenOrderTodayFile,VarRecRef);     //save as excel
        MailInt.AddAttachment(OpenOrderRangeFile);      //for attachment
    END
ELSE

Now, when I changed to SAVEASEXCEL, I get below err message:

Attachment c:\temp\OrderingReport_10_01_2014_10_14_2014.xls does not exist or can not be accessed from the program.

This is because the Excel file was not created.

Thoughts anyone?

*This post is locked for comments

  • mbr Profile Picture
    mbr 5,124 on at
    RE: Saving as Excel File with filter

    thank you Suresh.

  • Verified answer
    Suresh Kulla Profile Picture
    Suresh Kulla 43,745 on at
    RE: Saving as Excel File with filter
    TempFile.TEXTMODE(FALSE);
    TempFile.WRITEMODE(TRUE);
    OpenOrderRangeFile := TempFilename + 'OrderingReport_'+FORMAT(StartDate,0,'<Month,2>_<Day,2>_<Year4>')+'_'+FORMAT(EndDate,0,'<Month,2>_<Day,2>_<Year4>')+'.xls' ;
    TempFile.CREATE(OpenOrderRangeFile);
    TempFile.CLOSE;
    


    Please create the file first using above code then execute SAVEASEXCEL.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans