RW – Can I print Page Numbers including the Total Number of Pages?

David Meego - Click for blog homepageThis is a reposting of an article I originally wrote on my Developing for Dynamics GP blog.

The question in more detail is whether it is possible to print “Page: Y/X” or “Page: Y of X” on a Report Writer report, where Y is the current page number and X is the total number of pages for the report.

This question was asked again on the Partner Forum recently. It is one that has been asked on numerous occasions in the past and so I thought I would explain why the answer is “No …. well …. maybe”.

The Dynamics Report Writer is a single pass report writer.  This means it runs through the data once and prints section of each page as it is completed until it reaches the end. As it cannot tell in advance how much data is being printed and what additional headers and footers will be printed, it will not know the total number of pages until it finishes printing the last page.

So if we are talking about only using the Report Writer, then including the total number of pages is not possible.

OK, why did I say “maybe”?

If you really want this feature and are registered for Visual Basic for Applications (VBA), I believe it would be possible to estimate the number of pages. This is just a concept and to date I have not actually written the code.  You will need to decide if the amount of work required is worth the benefit of having the total number of pages.

You could use the Report_Start() event to read the legend values to get the range of records the report will be printing,  then you can create a connection to SQL Server via ADO (ActiveX Data Objects) and identify the amount of data.  For example: Identify a SOP transaction, read the number of lines and comments for those lines and lot and serial numbers for those lines.

Once you know how much data there is and how many lines can be printed on each page, you can calculate the estimated total number of pages.  Using the Report_BeforePH() event you can increment the number of the current page and then set a blank string calculated field to the value of “Page Y of X”.

There are some other aspects that should be looked at to help derive the formula for the number of lines that will be printed.  You need to take into account the restrictions on the report definition window as well as whether the body or additional headers and footers sections are suppressed for any conditions.  Finally, you can use the method in the post below to identify any additional restrictions added by the Dexterity calling code:

One final point to mention is that this technique will be more complex when the report is based off a temporary table.  When a temporary table is used, you would need to go back to the source data tables and reproduce some of the logic for creating the temporary table to identify the number of records that would be included in the temporary table.  While not impossible, extra work is required.

Please see the following post for more information on working with Report Writer, VBA and ADO:

Please add a comment if you have written something similar to this concept.

David

This article was originally posted on the Developing for Dynamics GP Blog and has been reposted on http://www.winthropdc.com/blog.

5 thoughts on “RW – Can I print Page Numbers including the Total Number of Pages?

  1. David, I’ve been promoting SQL Server Reporting Services to our clients for several years now.  I’ve always said that SSRS is a better tools than Crystal or GP Report Writer, except if you’re creating a customer-facing document such as a purchase order or invoice.  I just recently created my first SOP Invoice report in SSRS that supports batch printing (one report = multiple invoices), and learned that I was definutely correct.
    I’m sure some RW users would shout "Why doesn’t this tool support page numbers by transaction!"  Well,  SSRS has the same problem.  Overall, the invoice is pretty great, but page numbering was a real challenge.
    I eventually found a post (http://blogs.msdn.com/chrishays/archive/2006/01/05/ResetPageNumberOnGroup.aspx) from a SSRS team member on how to at least show the page number by group, but I seem to be completely unable to show "Page X of Y".  
    So, if anyone out there feels tempted to begin cursing RW, know that SSRS is not perfect either.
    Ron Draganowski
    Solution Services Practice Manager
    Olsen Thielen Technologies, Inc.
    St Paul, Minnesota
    rdrag@ottechnologies.com
    http://www.ottechnologies.com
    Find me on LinkedIn: http://www.linkedin.com/in/rondraganowski

    Like

  2. David,
    I have a question. How could I calculate the lines number for a report when the user can change the paper size or the orientation.
    I’ve tried in GP 10 the Report_GetPageSize but it loses GP with an error and if I try Report_GetPageRemaining I have an error too.
    Thanks, Ariel Laniado
    ariells@credivico.com.ar

    Like

  3. Ariel,
    The Report function library is only used for if you are creating a report on the fly such as what GP uses to print financials (balance sheet, etc).  That is why you don’t modify those report in report writer.
    You mention when you call this you "lose GP with an error" meaning a Watson error.  My guess is because in order to use this function you need to use Report_Begin().  But you cannot do this as a report is already printing.
    Yes I do understand that the user can change page size and orientation to mess up your page count.  However the approach to calculating the number of pages is completely depending on section size, page size etc, and if the end user is changing these things they’d really have to change the calucation.

    Like

  4. Hi Dave. I have a question. I need to use the Page Number in a formula, but if I use the global Page Number I allways get 0.
    How can I get the page number?
    Thanks, Ariel

    Like

  5. Ariel,
    Thanks for reading our blog – please note that the comments aren't really intended for questions on your own projects and more for comments about the article itself.
    As David points out in this article, you really cannot get the page number (or total pages) of the document.  You'd have to figure out a way to keep track of this yourself.
    You can maybe do it again by keeping track of the number lf lines on the report and then set/reset your counter as necessary.
    For questions on your own projects, I would ask that you ask your question i the Microsoft Dynamics GP forums or the Communities where all can contribute and share in the knowledge and solution.
    patrick

    Like

Please post feedback or comments

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.