Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate last page of a report?

Status
Not open for further replies.
Sep 13, 2002
28
US
I have a user that needs to have the page numbers in a report listed as 'Page 1 of x'. Before I go off and spend the time creating something (VFP8 has a _pagetotal system variable, but it doesn't work yet), has anyone done this already?

Thanks,

Bill
 
*Behind the scenes report to get page numbers
Public nTotalPages
Local cPathAndFile
REPORT FORM rptMyReport NOCONSOLE TO FILE &cPathAndFile
nTotalPages = _PAGENO
ERASE (cPathAndFile)

* Now do the same report again to the printer or preview window for the user...

"Page " + Transform(_Pageno) + " of " + transform(nTotalPages) &&Put this in your field expression Slighthaze = NULL
 
Thanks Slighthaze....

Your answer was basically the approach I was going to take... Can't wait for VFP8 to be released for real. The Beta is OK, but it's got lots of problems...

Thanks again....

Bill
 
BillGravell

[ol][li]Print your report twice once to a temp file and from there the system variable _PAGENO contains the total number of pages (since your at the last page). Store theis value to a public variable (nPages)[/li]
[li] Reprint your report to your printer and add a field at the footer of your report and put "Page number " +_pagegeno+" of "+nPages[/li][/ol]

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first or check this link
 
HI

First Run the report without an output..

myLastPage = 0

REPORT FORM myRptForm IN SCREEN NOCONSOLE

myLastPage = _PageNo

Now use this in your report..
REPORT FORM myRptForm PREVIEW TO PRINT PROMPT .. whatever

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
OK everybody....new kink in this one....

How can I make it respect the "Set page number to 1" on a new group?

Bill
 
HI
1. Open the Report in report designer.
2. Click on the REPORTS menu of tools bar
3. Click on Data Grouping..
4. Hilight the group in question.
5. Click on Reset Page number to 1 for each group
and save
You are done !
:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
If I do that (and I have tried) then the variable setup to store the last page of the report picks up the last page of the last group, and that is what I get on every page, regardless of what group it is printing....

I'm still trying to come up with a way of having it show "Page # of #" and have it respect the data grouping and resetting the page # to 1 after each group really messes it up.....
 
shot in the dark without having tried it...

can you use _PEPAGE to get the number of pages in the report instead of the _Pageno, or does it reset as well when you run the report with your data grouping page reset? Slighthaze = NULL
 
Dear all...

_pepage always returns 32767 on my machine, I think this is because it isn't supported and is included for backwards compatibility only.

The report to file is a good way, but can be VERY slow and generate VERY large files (I just tested it with a 17 page report and it made a 20MB file).

Ramani's method is somewhat hit and miss, the same report gave me a result 16 for the last page - when there were 17 in the finished report.

Does VFP8 include a better way?

I could dearly do with one!

TIA

Griff Regards

Griff
Keep [Smile]ing
 
From my reading (with VFP6) you have to print the report to file in order for the last page to be calculated correctly.

But you would have to give it a name that doesn't exist and of course it will double the time it takes to print the report.

Neil "I love work. I can sit and stare at it for hours..."
 
Griff,
As far as VFP 8.0 goes, yes there is a "better" way. If you include the _PAGETOTAL variable anywhere in the report, then VFP will automatically run the report for you twice! Note: If you use any UDFs that update tables you'll have to add checks to make sure they aren't run twice. While it may be a bit easier and more efficient that you running it twice, it still has to process all the records. I haven't seen a major difference in speed using _PAGETOTAL vs. doing it yourself.

Rick
 
To All....

I finally decided to write something in 7, since 8 is still beta and there's no guarantee that it will work the same when it's finally released.

To make everything respect the groups and reset page numbers on grouping, I resorted to printing to file. Since, most of the groups in this particular report are small, I wrote some code in the program that contains the SQL that creates the final dataset. After creating the dataset with a blank field for a group number, I update the cursor with a number of the group. I then determine how many groups that are..(with a select distinct on the group number I just populated). Then in a FOR...ENDFOR loop, create a public variable for each group. After creating the variables, I then run the report to file for each group, storing the _PAGENO variable to the variable that was created for that group previously. I then wrote a UDF and included it in the report field - "Page "+alltrim(str(_pageno))+" of "+setpage(). The UDF determines what group is being printed (from the group number put into the dataset earlier) and returns the page count for that group. If I can just figure out how to suppress the dialog that shows the print progress, it would be the final touch.

Lot to do, but in this case, it was very important for the user's department to have this.
 
Rick,

I just spent a happy half hour downloading vfp8 in beta and found the _pageTotal, which worked just as you said.

There almost certainly will be an advantage in speed - because it does an invisible run for the first pass - and I am hoping that this combined with the ability to print pages x to y will make my main problem go away!

Only snag is, I a) have to wait for non-beta b) update all my remote users with the support package c) by the looks of things vfp8 doesn't interpret the forms as I would have hoped (i.e. they look different) so I'll have to revisit every one of them to make sure they are OK!

Thanks for your help though!

Regards

Griff
Keep [Smile]ing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top