Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2020 : Technical Questions
Message Icon Topic: [CR2008] How to get the last record ? Post Reply Post New Topic
Author Message
.Spirit
Newbie
Newbie


Joined: 17 Aug 2011
Online Status: Offline
Posts: 3
Quote .Spirit Replybullet Topic: [CR2008] How to get the last record ?
    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 :


Thanks in advance !


Edited by .Spirit - 17 Aug 2011 at 5:11am
IP IP Logged
FrnhtGLI
Senior Member
Senior Member
Avatar

Joined: 22 May 2009
Online Status: Offline
Posts: 347
Quote FrnhtGLI Replybullet Posted: 17 Aug 2011 at 7:24am
Could you possibly use the maximum function?
|< /\ '][' ( )
IP IP Logged
.Spirit
Newbie
Newbie


Joined: 17 Aug 2011
Online Status: Offline
Posts: 3
Quote .Spirit Replybullet 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. ;-)
IP IP Logged
.Spirit
Newbie
Newbie


Joined: 17 Aug 2011
Online Status: Offline
Posts: 3
Quote .Spirit Replybullet 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 ;-)


Edited by .Spirit - 18 Aug 2011 at 3:28am
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet 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


Edited by lockwelle - 19 Aug 2011 at 3:32am
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.031 seconds.