Print Page | Close Window

[CR2008] How to get the last record ?

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=14110
Printed Date: 28 Apr 2024 at 2:03pm


Topic: [CR2008] How to get the last record ?
Posted By: .Spirit
Subject: [CR2008] How to get the last record ?
Date Posted: 17 Aug 2011 at 5:04am
Hi,

I'm using Crystal Reports 2008 and have a small problem with formulas.
I have created reports that, at the end, will be read through a VB.NET software.

Each report contains a diagram and, under this diagram, some figures.
I have managed to create the diagrams with values from an Access database.
But now I would like to get some particular figures, such as the last record read.

I can easily read the first record (onFirstRecord) but it does not work for the last record (with OnLastRecord).
I don't get it...

It looks like the currently read record is always the first.
So my question is: How to get the last record ?

Here is an example of the reports I'm working on :
http://imageshack.us/photo/my-images/402/crystalreports.gif/">

Thanks in advance !



Replies:
Posted By: FrnhtGLI
Date Posted: 17 Aug 2011 at 7:24am
Could you possibly use the maximum function?

-------------
|< /\ '][' ( )


Posted By: .Spirit
Date Posted: 17 Aug 2011 at 10:07pm
Hi,

Thank you for your answer.

That's what I'm using right now but, actually I can't. Some values sometimes decrease.
It only is possible on some rows that increase only (but even on those rows, sometimes there is an error in one record and the value become wrong).

Thanks. ;-)


Posted By: .Spirit
Date Posted: 18 Aug 2011 at 3:23am
I think I have a solution.

It's a little bit tricky but here it is:
In my VB.NET application, I can set a data source in my report (by executing a query on the Access database).
The solution consists in creating a subreport and setting another datasource (from another query that selects only the last row) to this subreport.

Then, in my subreport, I created a formula, declaring a shared variable, like that:
WhilePrintingRecords;
shared numbervar niveau_bac_phosphate_fin := {feuilledequart.niveau_bac_phosphate};

The formula has to be added to the report (in any section). However, it is possible to hide the section so that it does not appear. Moreover, it is possible to remove the black borders from the subreport. After that, your subreport is totally invisible.

As for my report, I declare the same variable (without assigning a value):
WhilePrintingRecords;
shared numbervar niveau_bac_phosphate_fin;


And I can use it in the report.
Note that the subreports must be in a section that is above the section where your formulas (the one in which you use the shared variable) are. It cannot even be in the same section.

I know it is tricky as hell but it is this only solution I have found... I've been searching for 3 days :-D

Bye ;-)


Posted By: lockwelle
Date Posted: 19 Aug 2011 at 3:31am
Just some other alternatives that came to mind....
 
I can see the subreport as the solution, though if you are setting the datasource in .Net, why not just add a column and populate it in the code (an id or a t/f flag).
 
I guess I am bit confused, do you just want to notify what the last record was or are you looking to only display the last record?
 
Obviously, if you just want to display the last record, filter the data on the .Net side and return just the row you want.
 
If you want to notify which record was the last one read, I would create a formula like:
shared numbervar aLast := {table.field};
"" // makes the formula invisible
 
then when you want to display the value:
shared numbervar aLast;
aLast
 
Of course you can change what is stored to whatever values you truly want to display.
 
While you are setting the datasource from .Net, which means that CR is not really hitting the database again, I prefer to avoid subreports where possible...I feel it is just a cleaner solution
 
But if you found something that works, who am I to second guess.
 
HTH



Print Page | Close Window