# Codeunit to save report as pdf fails to work correctly

**URL:** <https://www.dynamicsuser.net/t/codeunit-to-save-report-as-pdf-fails-to-work-correctly/45216>\
**Category:** Developers Forum\
**Created:** [April 10, 2013, 10:45am UTC](https://www.dynamicsuser.net/t/codeunit-to-save-report-as-pdf-fails-to-work-correctly/45216 "2013-04-10T10:45:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![talkster5](https://avatars.discourse-cdn.com/v4/letter/t/ccd318/32.png) [@talkster5](https://www.dynamicsuser.net/u/talkster5)\
**Post date:** [April 10, 2013, 10:45am UTC](https://www.dynamicsuser.net/t/codeunit-to-save-report-as-pdf-fails-to-work-correctly/45216/1 "2013-04-10T10:45:48Z")

</div>

Hi,  
I have been trying to construct a codeunit to save a report as a pdf which works for thing’s like invoices and quotes where I just need to pass a simple filter with the document number however now I am trying to use the same code for generating a statement which requires 2 parameters and I can’t seem to get it to work correctly.

The codeunit executes correctly and using procmon I can see the access attempt on the directory and the file being written but NAV then deletes the pdf files which I presume is because it contains no data. If I run the report manually with the same filters however it generates without any problems.

I presume I have probably gone wrong with my filters in the codeunit which is why it is not finding data so I would appreciate it if anyone could shed some light on it.

FileName:=‘C:\statements\statement.pdf’;  
Customer.SETFILTER(“No.”,‘01147514’);  
Customer.SETRANGE(“Date Filter”,01012007D,10042013D);  
repStatement.SETTABLEVIEW(Customer);  
repStatement.SAVEASPDF(FileName);

The above code I originally found on a blog for generating invoices however I can’t remember the link to provide it as a reference. The repStatement is set as a variable to our RTC statement report.
