Shared Variables - HELP

:hb:
I have read and read about shared variables and tried almost everything that I have read and I just can’t seem to get mine to work.

I have a stored procedure in the main report that has my account number in it and I want it to print in my subreport, the stored procedure there does not have the account number.

In the main report I set up the following formula:
WhilePrintingRecords;
shared StringVar AcctNum := {TABLE.AccountNumber};

In the subreport the formula is:
WhilePrintingRecords;
Shared StringVar AcctNum;

I do not print in the main report before I print the subreport and the subreport is in a GroupFooter of the main report. Also, in the subreport I am further selecting my records with the select expert so that I filter out things that I do not want to print.

I put the WhilePrintingRecords in my formula and have not put it in. I have tried using a shared variable that does a count of what I am printing in the subreport and then print my account number in an additional group footer if the count is not 0, but the count does not pass to the main report either. The count is correct if I put it in the subreport just to see what it is.

I am doing something wrong and since I am so new to Crystal I can not figure it out. I really need to make this work and any help would be so appreciated. I have already spent a good 8 hours on it.

Peggy


peggall :us: (BOB member since 2009-07-23)

I have not had great luck with shared variables either because typically I need them before they would otherwise be available. But in your case have you considered just creating a parameter on your sub-report which becomes a field or doesn’t even do anything like

‘{?account}’ = ‘{?account}’

Have the main report pass it as a parameter and then you can print it on the sub-report.


BDeLong (BOB member since 2008-01-15)

Does it matter that the parameter is not part of the stored procedure?


peggall :us: (BOB member since 2009-07-23)

Hi, Peggy.

Did you resolve this? It may just be a matter of where you place the formulas in the main report and the subreport.


lgonzalez (BOB member since 2002-07-17)

No I did not resolve this and would really like to get it working if you might be of assistance. Thanks. :hb:


peggall :us: (BOB member since 2009-07-23)

Sure! I hope I can help.

How are you using the formula in the main report? Where in the report did you place it? Does it work on the main report to display the account number you expect?


lgonzalez (BOB member since 2002-07-17)

I had a result field in the main part of the report for my account number and it was coded like: shared StringVar AcctNo := {myfile.AcctNum};

I am not printing anything in the main part of the report.

I have a subreport, at the account number footer break and I wanted to print the account number shared variable in the detail portion only when certain criteria was met.

I hope all of this made sense.

I am using stored procedures, which I can not change and I can not use SQL to only get what I need - many many reasons why.


peggall :us: (BOB member since 2009-07-23)

Hi, Peggy.

See if we can get on the same page…

  • In the main report, you have a formula field (what’s it called?) whose formula is:
    WhilePrintingRecords;
    shared StringVar AcctNum := {TABLE.AccountNumber};

  • In which report section do you use this field? Report Header? Group Header?

  • It sounds like you have a Group defined on AccountNumber, or at least on something that yields a unique AccountNumer per group or page. Is this correct? Please explain exactly how you intend the report to work. I ask because passing the value of the variable will work as you set it up only if you pass a single value and will not work if there are multiple values of AccountNumber that it is trying to pass. And it should be used in the report, even if you suppress the section in which you use it. If it’s not in the report, it’s not processed.

  • In the subreport, you have a formula field (what’s it called?) whose formula is:
    WhilePrintingRecords;
    shared StringVar AcctNum;

  • In which report section do you use this field?


lgonzalez (BOB member since 2002-07-17)

Here are the answers to your questions
The name of the formual field in the main report is RepAcctNum

I do now have it in any report section of the main report.

Yes, I do have a Group defined on the accountnumber.

The formula field in the subreport is SubAccountNumber

How I want the report to work is to pass the acount number to the subreport and for that account number to print in the subreport if my selection criteria, which I am doing in the Select Expert because I can not change the store procedure, is met.

The subreport is in the Group footer of the accountnumber. The accountnumber is the only grouping that I have.

I hope this helps.


peggall :us: (BOB member since 2009-07-23)

Hi, Peggy.

So I think the only issue is:

For the formula in the formula field to be processed by the report, it has to be used in the report canvas. So go ahead an put it in the group header. You can suppress the field once it’s on the canvas (that just keeps it from displaying on the report, but it is still processed), and you can do that either by suppressing the field or suppressing the section into which you place it (if you were to insert a section in the group header specifically for it).


lgonzalez (BOB member since 2002-07-17)

Luis,
Thank you so very much :D. I got the results that I was wanting once I put the formula field in the group header for the account number.

Just one little thing, that is usually the way that it is.
Peggy


peggall :us: (BOB member since 2009-07-23)

You’re welcome. :slight_smile:

And yes, that is the way it has to be. In Crystal, a field is not actually used by the report unless it has a green check mark on it in the Field Explorer. It gets a green check mark when it is processed – when it’s on the report canvas or when it’s used in some other formula that is used in the canvas or in a record selection.


lgonzalez (BOB member since 2002-07-17)

Thank you both Peggall and Igonzalez, you have just saved my tail … with this forum chat now I can use Shared Variables.


bill.nickles (BOB member since 2009-10-22)

You’re welcome!
:smiley:


lgonzalez (BOB member since 2002-07-17)

Thanks you guyz, was helpful…


northwest (BOB member since 2009-06-16)