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!

Getting the last record from detail section in header section 3

Status
Not open for further replies.

patox

Programmer
Dec 10, 2014
4
CL
Hi everyone!, I'm a bit new to Crystal Reports and having a big problem (at least big for me)...I need to get a last record field from the detail section and show it in the header section. I'm using the following two simple formulas:

//------------------------------------------------------
Header section:

//Formula1 (just for showing the variable got from Formula2)
whileprintingrecords;
shared numbervar Saldo;

//------------------------------------------------------
Detail section:

//Formula2
whileprintingrecords;
shared numbervar Saldo;
if onlastrecord = true then Saldo:={spKardex_CodZOFRI.amount};

//------------------------------------------------------

Ex. for a 4 records dataset:
1- 255
2- 122
3- 69
4- 56

I'm always getting the first amount (in this case 255) but I need the last one (56) on my header section.

What am I doing wrong??? thanks in advance



 
If your detail records are in descending order like your example, then you can create a Summary in the header that is Minimum({field})
 
Hi again, thanks for answering Charliy, I just tried your suggestion but It doesn't work either. Unfortunately, It seems the next paragraph (I got from another forum) is the right answer:

"You're not doing anything wrong - it's a shortcoming of Crystal that you are battling.
Basically, CR cannot determine the "last" record in a section until it has printed it, and by that point it is too late to show it in the section header!
The workarounds include:
a) "Sod it, I'll put it in the section footer"
and
b) "I'll have to add another (or modify the) data source on my report to provide this value for me
Sorry dude,
George"


Regards! Patrick
 
Hi Bettyj, yes I am, I must show the quantities descending in the detail section and the lowest number should appear in header.

Regards,
Patrick
 
I think you can achieve this by creating a subreport. Sort details in ascending order in the subreport. Copy the amount from the detail to the Group Header in the subreport.Suppress all other sections of the subreport except GH. Place the subreport in the GH of the main report.
 
Charliy's method works. It is much easier than using subreports.
 
Ups!! You are totally right Bettyj, Charliy's solution works fantastic!! I tried it earlier but I had deleted some records, that's why I couldn't realized it, I almost gave up, thank you guys for your help![bigsmile]

Best regards!
Patrick
 
Hi Patrick

Given Charliy's and BettyJ's suggestions worked so well, the appropriate way to thank them is through the use of the purple star, using the "Like this post? Star it?" link.

As well as showing appreciation for them taking the time to help, it also indicates to others what actually helped you achieve whet you needed.

Regards
Pete

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top