user3756189
user3756189

Reputation: 13

Getting the last record from detail section in header section

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:

//Formula 1 (just for showing the variable got from Formula 2)

whileprintingrecords; shared numbervar Saldo;

Detail section:

//Formula 2

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.

Upvotes: 0

Views: 1935

Answers (2)

R. McMillan
R. McMillan

Reputation: 1422

Unfortunately that formula won't work in a header section due to how Crystal Reports works. When a report is generated CR doesn't read the entire data set before it begins printing the sections. When a header section is printed, CR has only read the first record in the data set, or the first record in grouped data within your data set. There are functions that allow you to read the values of the previous record, or the next record, but the rest of the data set is out of scope. So once the report begins printing even the first record in the details section, all header sections have already been printed completely and cannot be altered.

Your formula would work in the footer section, but the OnLastRecord = true portion would be considered redundant since the report is always on the last record when printing a footer section. The usage of OnLastRecord is usually only used to allow formatting control within the last record of the details section.

If you a specific need for values from the last record of the detail section to be shown in the header section, you will need to use either a SQL Expression Field or a Subreport.

Upvotes: 1

TheOne__
TheOne__

Reputation: 426

If your detail records are in descending order like your example, then create a Summary in the header that is Minimum({field}).

Upvotes: 0

Related Questions