tags:

views:

182

answers:

1

I have a report (using VFP 8.0) with a data grouping by Invoice Number, i need to reset the total of pages by changing of invoice number.

I failed to do so, as the _pagetotal will always return total pages of all selected invoice.

Please advice.

A: 

Based on the description, it appears what you want is per my earlier comment... Each invoice has its OWN Page X of Y context where some "groups" have more pages than others. To do what you want typically requires the report to be generated TWICE. Once to run and capture the how many pages at the end of each group. The second instance is the "FINAL". The following is a simple sample on how to do such.

Create your query results, but add an additional column "OfPages" (or whatever you want to represent the per "group" Of Pages count) into a readwrite cursor.

SELECT YourIDGroup, OtherColumns, 000 as OfPages;
    FROM YourTable;
    ORDER BY 1;
    INTO CURSOR C_YourReportCursor readwrite


REPORT FORM TmpPages

REPORT FORM TmpPages preview  (or to printer)

Next, in your program, have a function to "catch" the page number at the group footer for whatever your current ID is.

FUNCTION CatchOfPages
   LPARAMETERS CurrentID, LastPg

   UPDATE DBF( "C_YourReportCursor" );
      SET OfPages = LastPg;
      WHERE YourIDGroup = CurrentID

   */ Return empty space so nothing is actually printed in the report
   RETURN ""
ENDFUNC 

Now, the trick. In your report, have your data group based on the ID of the invoice. In the group header, instead of doing page x of y using _pageno and _pagetotal, you will be using _pageno and the column "ofPages" of the cursor... As the first pass will get its proper value updated via the function call above and is set the first time the report is generated but to no output window or printer, just run in the background.

Now, in the group FOOTER, at the bottom, add a textbox control (just as if any other data field output), and set its Expression = the function call with the respectible parameters... ex:

CatchOfPages( YourIDGroup, _PageNo )

It will do the update to the temp cursor (or your result table) with whatever its actual page number is for that final page to the group, and update all records for the associated invoice ID Group, so even page 1 knows its OfPages = 2, 3, 4, or whatever.

To hide / mask the first instance of the report from being seen, hide it in ANOTHER Window, such as

DEFINE WINDOW WinTempReport FROM 0, 0 TO 1, 1
REPORT FORM YourReport IN WINDOW WinTempReport
RELEASE WINDOWS WinTempReport

THEN do your report to normal output.

DRapp
Hi DRapp, Thanks for your helps! You advice is working great! In order not to show the report at the first time Which command i should use? I try to put REPORT FORM TmpPages NoConsoleit won't calculate the total pages...Please help!
Andrea.Ko
Just like above, REPORT FORM YourReport, no need for to print, preview, nothing.. just run the report. It will basically run in the background and generate all the pages. The SECOND instance include your output direction to print or preview. It will already have the final page counts per ID group
DRapp
Thanks for your fast reply.I am not sure if it is due to my vfp setting, it won't run in the background but showing all the reports on my screen. That's why i included "REPORT FORM tmpages NoConsole" on my forms.
Andrea.Ko
Added masking of report to bottom of original solution.
DRapp
Hi Andrea, just an FYI. In support forums, such as this, its a courtesy for others searching for issues to find the answers that "worked". As such, when you go back to your questions and DO find the answer that works, there should be a checkbox under the up/down counters per answer. Click that to indicate "This was the solution that worked". Then, in future, others can jump write to a given solution.
DRapp
Thanks for your advice. I just realize that since i am a newbie here :P Btw, i just clicked that icon :) Again, Thanks for your help! Really appreciate it!
Andrea.Ko