Formula field in Report Header....

Dear Experts,
->Formula @Source:
Shared stringvar strval;
if recordnumber > 1 and {StoredProcedure_SP;1.ID} <> previous({StoredProcedure_SP;1.ID}) then
      strval:= "BOTH"
Else
      {StoredProcedure_SP;1.ClientS}

->Formula @Test:
shared stringvar strval;
strval;


-> My report is pulling 3 records from the database.
I kept following fields in my detail section of the report: ID,@Test,@Source
My report shows following values for above 3 items(ID,@Test,@Source):

Result:

2            CS
3      BOTH      BOTH
3      BOTH      RE

@Test formula shows result "BOTH" in 2nd row because value of ID is different compare to first row,which is right.But now if i put another @Test formula in REPORT HEADER section than it is not showing me anything over there but it is still showing me values in DETAIL section of the report.

Some or how i want to display "BOTH" in REPORT HEADER section when value of ID change as i wrote in @Source formula. Please let me know how do i do that ?

Thanks.
bhavesh55Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bhavesh55Author Commented:
First record of @Test formula is "blank" space(does not show anything).

Thanks.
mlmccCommented:
The report header is built only once and the only record available to it is the first record therefore there is no way the value has changed since the previous record doesn't exist.

What are you trying to do?

mlmcc

bhavesh55Author Commented:
Hi mlmcc,
Whatever the records report is retrieving, if it has MORE THAN ONE DIFFERENT kinds of values in "ID" field(e.g. here we have two different ID = 2 & 3) than i want to change the report header(="BOTH"), otherwise value of report header will come from database if all records of the  report has SAME VALUE of field ID.

I am trying to do this logic:
when first condition becomes true in Formula @Source, than strval:= "BOTH" that value i want to display in Report header.So value of strval i am trying to pass to another formula which is @test so that formula can display the STORED value of variable strval in report header.

So Please let me know as soon as possible if there is some other way of doing it.

Thanks.
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

mlmccCommented:
The only way to do this is to put a subreport in the report header that figures out whether to say both or use the value.

In the subreport
Global Report header add a formula
Global NumberVar CurrentID := {IDField};
StringVar Heading := ToText ({IDField},0);

In the detail section
Global NumberVar CurrentID;
Global StringVar Heading;
If CurrentID <> {IDField} then
  Heading := "Both"

In the report footer
Global StringVar Heading;
  Heading

Put the subreport in the report header.  It should just show the proper value.

mlmcc
bhavesh55Author Commented:
Hi mlmcc,
Sorry for the delay. Actually i was too busy.Where do you want me to put above mentioned 3 sets of lines ?

In the subreport, do you want me to put below 2 lines in one formula and put that formula in subreport's report header ? Please advice.

Global NumberVar CurrentID := {IDField};
StringVar Heading := ToText ({IDField},0);


In the detail section, you want me to put these 4 lines in one formula and put that formula in subreport's detail section or main report's detail section ? please advice.

Global NumberVar CurrentID;
Global StringVar Heading;
If CurrentID <> {IDField} then
  Heading := "Both"


In the report footer,you want me to put these 2 lines in one formula of main report or sub report ?
Global StringVar Heading;
  Heading

Thanks.
mlmccCommented:
Not sure.  Let me review the question and remember what I was thinking

mlmcc
bhavesh55Author Commented:
Hi mlmcc,
you didn't get a chance to review the question like where do i put those formulas ?

Thanks,
bob
mlmccCommented:
Sorry.  Lost track of this.  It took me some time tonight to figure out what I was trying to suggest.

Put a subreport in the Main report header

In the subreport Report Header
Formula - DeclVars
WhilePrintingRecords;
Global NumberVar CurrentID := {IDField};
StringVar Heading := ToText ({IDField},0);

In the subreport Details
WhilePrintingRecords;
Global NumberVar CurrentID;
Global StringVar Heading;
If CurrentID <> {IDField} then
  Heading := "Both"

In the subreport Report Footer
WhilePrintingRecords;
Global StringVar Heading;
  Heading

Use the same SQL or tables for the subreport

mlmcc

GranModCommented:
PAQed with points refunded (125)

GranMod
Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.