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!

Shared variable showing up incorrectly

Status
Not open for further replies.

JCruz063

Programmer
Feb 21, 2003
716
US
Hi guys!
Crystal Reports 10.

I'm trying to update a shared variable in a subreport and display it in the main report. I'm a bit puzzled.

What I'm doing is this: In the Page Header of the main report, I'm setting the variable to 0. My main report contains a group, and on the group footer, I have the subreport. The subreport itself contains a group, and in that group footer, I'm updating the shared variable. Now on the page footer of the main report, I want to display the variable, but it's not showing up as I expect it.

Here's how the whole thing looks, assuming that x is the shared variable (SR = subreport):

[tt]Main Report
Page Header >> x := 0;
Group1 Header
Group1 Footer (Subreport is here)
SR:Group1 Header
SR:Group1 Footer >> x := x + 1;
Page Footer >> (display x)[/tt]

Let me explain a bit more.

The subreport
The subreport displayes a list of users. The group in the subreport groups records by a user field in the database, and thus, each value in the footer of the group will be a different user. Right on this footer, I have a formula which increments the shared variable by 1. Each user is printed on a different row, and there is a total of 37 users, 29 of which fit on the first page. The rest are displayed on a second page.

The main report
The main report groups records by month (based on a date field) and it doesn't see any users. The subreport is in the group footer. For every month, the entire list of users is printed (i.e. the subreport is displayed). Thus for every different group (month) value in the main report, the subreport prints two pages (29 users on the first page, 8 on the second).

The Problem
With the setup above, the x shared variable is coming up as 0 on the first page, even though it should be 29. For every page after the first one, x is coming up as 37.

I'm expecting x to be 29 on the first page of every month, and 37 on the second page of every month. Am I missing something?

Thanks.

JC

_________________________________________________
To get the best response to a question, read faq222-2244.
 
The subreport executes as an entire object, not per page. If the same numbers are always involved, why not add a formula to the page footer:

if pagenumber = 1 then 29 else 37

-LB
 
Thanks LB.

The number of users will vary depending on different factors (time included). Those numbers are true for the data I'm testing.

What I'm trying to do is display a footer at the bottom of the page for each non-completed month, that says "Continued on next page". In other words, say I'm printing July and August. Pages 1 and 2 will be July, and 3 and 4 will be August. Pages 1 and 3 should have a footer saying "Continued on next page", but not 2 and 4.

I noticed that the maximum number of users that could be diplayed per page is 29, and so I created a shared variable to keep track of the number of users that have currently been printed. When I reach 29, I would display the footer in the main report, and reset the variable. Obviously this doesn't work.

Given my setup, how do think I could get that footer in?

Thanks.

JC


_________________________________
I think, therefore I am. [Rene Descartes]
 
You could use a formula like:

whileprintingrecords;
numbervar x;

if pagenumber in [1,3] then 29 else x

Place this is the main report page footer.

-LB
 
Maybe something like this would work:
Add the text box with "Continued on next page" as the text in your page footer. Then conditionally suppress the box if:
{table.month} <> Next{table.month}

MrBill
 
Thanks guys!

MrBill,
I had tried that also, but {table.month} and next{table.month} are always different (I'm not quite clear why).

The set of records in the main report is different from that of the subreport. Saying next({command.month}) in the main report is returning the next month value of the records in the main report. Because the subreport runs as whole object, it appears that the main report is not aware of the multiple pages it's producing. Either that or something close. As of now though, in the page footer of the main report, {command.month} and next({command.month}) always show different values.

Any other ideas?

LB,
I'm not sure how many users I'll have at run time, and thus I can't hard code page numbers like that.

Thanks!

JC

_________________________________
I think, therefore I am. [Rene Descartes]
 
My suggestion only hard codes the number of records shown on the first page, since you said the first page can only hold 29 users. If there can be less than 29, then use a formula like:

whileprintingrecords;
numbervar x;

if x < 29 then x else
if pagenumber in [1,3] then 29 else x

-LB
 
LB, Thanks again. Sorry I'm a bit late with my response!

OK, the requirements for this report changed a bit. The number of users (rows) printed will not be fixed. It will change from month to month. Previously, the number of users per month was always the same, although I didn't know how many users there were.

Given this, and the setup that I originally posted in the first thread here, how can I accomplish printing a footer at the bottom of the page only when all the users of a given month have not been printed? Any ideas?

Thanks.

JC

_________________________________
I think, therefore I am. [Rene Descartes]
 
If the users fit on one page, then the subreport will be executed before the page footer and x will <> 0, but if it doesn't, x will = 0, so you could use a formula like:

whileprintingrecords;
shared numbervar x;

if x = 0 then "Continued" //or whatever you want to say
else ""

This assumes you have an initialization formula in your report header setting x := 0, and that you still have the shared variable formula in your subreport. (Note that I forgot to identify the variable as a shared variable in previous suggestions).

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top