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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing variables to Main Report

Status
Not open for further replies.

AyJayEL

Technical User
Jan 30, 2001
425
GB
I have a report with a subreport. I have declared a shared stringvar which I want to use to pass a value from the subreport to the main. I have a formula {@ChangeSame}that shows where the next record is different. It says 'Same' or 'Change'. The show formula says
whileprintingrecords;
shared stringvar Pass := {@ChangeSame}

I want it to pick up the first records {@ChangeSame} value but it picks up the last one which is blank. If I change the @ChangeSame formula to previous record it will pick up the last record which can be wrong ie in these cases

For Next @ChangeSame
1 George School Change
2 Fred School Same
3 Fred School

Show = Blank (Incorrect)

For Next @Change Same
1 David School Change
2 Martin School

Show = Blank (Incorrect)

For Previous @ChangeSame
1 George School
2 Fred School Change
3 Fred School Same

Show = Same (Incorrect)

For Previous @ChangeSame
1 David School
2 Martin School Change

Show Change (Correct)

I only want to compare the first two schools in the list and can suppress the others but the formula still looks at all the records. I have tried using minimum in the show field but it won't allow me.

Any ideas? Learn something new every day *:->*
 
Can I ask why you are doing this? It looks like you might be listing a childs school history and comparing that to their current school.

That might explain why you have the subreport and want to show whether the first school name is different to the second school name.

Please elaborate a little more. Steve Phillips, Crystal Consultant
 
Yes Steve, I am looking at a child's school history and comparing it to their current school although I am looking at the type of school to see whether it is different. ie if it is a Special School, an ordinary LEA school, Independent etc. The user wants to see if a child changes from a special school to an ordinary school or vice versa etc. I can show that fine. What I need to do in the main report is to suppress the groups (child group) and details where there is no change, therefore I need to pass the Change or Same record back to the main report.

Is that enough? :) Learn something new every day *:->*
 
You need to use a shared variable that is accessible to both the sub report and the main report.

It should simply return a True or False depending on whether the school type changed in the subreport.

Call the subreport at the child group header level (in the main report) to ensure it returns the T or F at the earliest opportunity. You will then be able to conditionally supress the remaining sections relating to the child.

You will encounter problems though with this kind of report. Even though you will be able to supress nearly all the sections, you cannot suppress the section with the sub report in.

There are many ways of making this as invisible as possible but it may still cause some blank areas in the final report.

Are you sure you need subreports at all? They make a report much slower and should be avoided unless absolutely necessary. In your case, I don't believe you need one at all. And, it might be possible to get rid of the empty space you'll get with your current solution. Steve Phillips, Crystal Consultant
 
Steve

The result is passed back the main report fine. It says changed or same instead of true or false but it means the same I guess. The problem I have is in the subreport. I have to use a subreport because I am using a date parameter on the date the child started at the school. If the school history is not in a subreport it only brings out the present school.

If you look in my original post you will see that the results of the Change/Same formula works in this way.

First record blank
second record either change or same.

If there are only two schools this is fine because it passes the last record across. But if the child has had a few moves the last record may be incorrect.

ie

1 Fred School (Blank)
2 George School (Change, different from 1st school)
3 George School (Same, same as previous school)

In this case Same would be passed to the main report even if I suppress and schools after the first two.

If I use next in the formula I get the blank field as the last record and that gets passed to the main report.

Is that any clearer? Learn something new every day *:->*
 
In the formula, test whether the value is "Same" or "Change". If its "change" already, there's no need to do anything.

As you are only trying to test for a change, you do not want to allow it to go from change to same.

Post your formula if you want specifics.

Steve Phillips, Crystal Consultant
 
Here are the two relevant formulae. In order to simplify my explanation I just said change of school but in fact it is change of type of school, hence the criteria formulae.

Change/Same Formula
if({@Criteria1}=Next({@Criteria1}))then "Same" else
if ({@Criteria1}<>Next({@Criteria1}))then &quot;Change&quot;

Critria1 Formula
if {BASES.TYPE_ID} in [&quot;ACE&quot;,&quot;AEO&quot;,&quot;CCS&quot;,&quot;CH&quot;,&quot;FS&quot;,&quot;GRS&quot;,&quot;INF&quot;,&quot;JUN&quot;,&quot;MON&quot;,&quot;MS&quot;,&quot;NM&quot;,&quot;NOR&quot;,&quot;NRV&quot;,&quot;OTH&quot;,&quot;NS&quot;,&quot;PLY&quot;,&quot;PRE&quot;,&quot;PRI&quot;,&quot;PRU&quot;,&quot;UPS&quot;,&quot;VOL&quot;] THEN &quot;In County Non Special&quot;
else if {BASES.TYPE_ID} in [&quot;EOT&quot;,&quot;NOR&quot;,&quot;OTH&quot;] then &quot;EOT, NOR or OTH&quot;else
if {BASES.TYPE_ID} in [&quot;SEN&quot;, &quot;SS&quot;] then &quot;Special&quot;
else if {BASES.TYPE_ID} in [&quot;COS&quot;, &quot;OLM&quot;, &quot;OLS&quot;] then &quot;Out&quot; else
if {BASES.TYPE_ID} = [&quot;PCC&quot;] then &quot;Private Children's Home&quot; else
if {BASES.TYPE_ID} = &quot;IND&quot; then &quot;Independent&quot; else &quot;Other&quot;


Many, many thanks for looking at this for me Steve. Learn something new every day *:->*
 
You need to solve this problem with variables in the subreport.

Change the formula to

WhilePrintingRecords;
StringVar StateChange;
if StateChange <> &quot;Change&quot; then
if ({@Criteria1}<>Next({@Criteria1}))then &quot;Change&quot;;

Insert this in the SubReport Details section

You will also need a reset formula such as:

@ResetState
WhiePrintingRecords;
StringVar StateChange:=&quot;&quot;

This needs to be inserted in the SubReport RH section.

And finally, you need a formula to show the result of the variable:

@ShowState
WhilePrintingRecords;
StringVar StateChange;

This should be inserted in the SubReport RF section.

Only the &quot;show&quot; formula needs to be visible, the others can be supressed. The main report will now show blank or &quot;Change&quot;. If you want the default to be anything other than blank, change the Reset formula. Steve Phillips, Crystal Consultant
 
Sorry, the calculation formula should be:

WhilePrintingRecords;
StringVar StateChange;
if StateChange <> &quot;Change&quot; then
if ({@Criteria1}<>Next({@Criteria1}))then StateChange := &quot;Change&quot;;
Steve Phillips, Crystal Consultant
 
Sorry to butt in at this late stage, but may I ask what the impact would be of doing something like:
Code:
WhilePrintingRecords;
StringVar FirstSchool := Minimum({School},{Kid})
Shared StringVar ChangeSame;

If {School} <> FirstSchool
Then ChangeSame := 'Change'
Else ChangeSame := 'Same'
and placing this in the subreport section which returns the school information?

It seems to me that your problems are occuring because you are trying to rely on 'Next' and 'Previous'. Considering you have no cap on the number of schools in a group, I doubt you should be getting entangled with those two functions in the first place.

Naith
 
Naith, I agree this can be solved in a number of ways, but in this case, its not the school change that's important its the school type.

You could compare the mimumim school type with the maximum school type - if they are different, they have changed school types. Note that the SubReport is run for EVERY child so we would be working with Grand totals not Sub totals.

My solution works with what Andy already has in her report.

As Andy already had Next and Previous, it seemed sensible to work with that but ageed, there are more efficient ways. Steve Phillips, Crystal Consultant
 
I guess we must have posted at the same time. I didn't see your final solution. Sorry if I confused the issue.

Naith
 
The problem with using minimum and maximum school types is I only want to see if they have changed from their last move. I am not interested in previous changes.

I already had a reset and show formulae but didn't mention them as I took them as given.

I am now trying out Steve's ideas in the message before last.

Andrea

Thank you for sparing your time to look at this. My hero's!!! Learn something new every day *:->*
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top