Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subreport shared variables and more question

Status
Not open for further replies.

subbie1268

Programmer
Dec 11, 2003
6
FR
First off, I would like to thank all you guys out there that respond to peoples posts, I pretty much learned how to do subreports and other things in crystal just by reading other peoples questions they had and answers that were provided. So Thanks again, any help on this will be greatly appreciated, because I have been stressing trying to figure this out, I will try to be detailed as possible.

I have created a billing statement report, on the first group of the report I have billing contact information and total balance due, the second is a detail break down of the charges using the 0-30, 31-60, 61-90, 90+. The third group has running total fields of the 0-30, 31-60, 61-90, 90+ and also another field that says total balance(same forumla as the one in group 1). The original problem I had (which I still have) is that the total balance in the first group is not correct if a person has more than one charge, I have realized why because it is only grabbing the value of the first record, because the second group hasnt been run. However the 3rd groups total balance works great.
I have read the forms and I saw some similar questions, and peoples answers where to do subreports. So I started researching on here and in crystals help about subreports, and I created one. It came out nice, I checked all the data and it looks good. I did the shared variables, everything looks good. In the subreport I have 2 groups the customer number and 2nd group is a balance field. I have a running total occuring on the balance that breaks on change of customer number. My problem is now the shared variables I put on the main report are only grabbing the data from the first entries on the sub report. Here is an example and I will just build the first group since that is the problem area

Main Report Layout

Customer #
Customer Name Total Balance Due
Address1
Address2
City,State Zip

Subreport Layout
Customer #, Customer Bal, Running Total(customer bal)

Data Example (first 2 records from main report and sub report)

Main Report:

43311
John Smith
234 Main St Total Balace: $75.00
Suite: 101
Miami, Fl 33193

48970
Jack Dawson
544 Main St Total Balace: $75.00
Suite: 500
Miami, Fl 33193

Sub Report:

43311, 25.00, 75.00 (2 charges 1 is 50, 2nd is 25 so total is 75)
48970, 15.00, 50.00 (same as above jsut different amounts)

The problem is that the second bill still is carrying over the balance of the first guy even tho when I look at the subreport the correct balance for him is 50.00.
I have trie to due an array but what occurs on the print out is that only 1 person is getting a total balance printed on the top. Is it possible to get the correct balances from the subreport to appear on the main report rather than looping te first balance on to every one?

Perhaps what I am trying to do is not possible or I am approaching it in a way that is not logical, I am open to any idea and suggestions and anything will be appreciated. I hope I have provided enough information and at the same time havent caused you to fall asleep. Thanks again for your time.
 
You've neglcted to mention a few things that might help.

What version of CR?
Where is the Sub-Report placed in the report, i.e. report header, page header, group header 1 etc.

from the results you are experiencing, It looks like you are not passing back the shared variable for each group....


Reebo
UK

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."
- Albert Einstein (1879-1955)
 
I figured I left something out, sorry about that. I am using CR 8.5. I have tried 2 different places to place the subreport, I have placed it in the same group as the total I needed and I have tried to place it in the page header, because on the patient footer I do a page break. I hope I answered what you need, thanks in advance
 
OK, the problem here is how you are using the Sub-Report.

Right click to the left of the group header and select inser section below. Then move everything from GroupHeadera to GroupHeaderb.

Place the subreport in GroupHeadera.

We are doing this as the subreport needs to be run before we use the result. To explain, crystal works in a modular fashion. Things are queried as they appear on the report. Therefore, if we want to use the calculation from a sub-report, the sub-report has to have been run before we can use the calculation.

Now you have the sub-report in the group header, you need to link it to the customer number. right click the sub report and choose Change sub report links.

Select the customer number from the main report and the sub report.

Preview the report and let me know what happens....



Reebo
UK

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."
- Albert Einstein (1879-1955)
 
Thanks reebo, I have tried that and I am now getting 0 in my main report. Maybe there is something I need to change in my formulas? Here are the 2 forumlas I am using

Main Report:

//@MainFormula

WhilePrintingRecords;
Shared CurrencyVar myTotal;
myTotal

Subreport:
//@SubFormula

WhilePrintingRecords;
Shared CurrencyVar myTotal;
myTotal := sum({Balance})
 
Where is the subreport in the main report?

Reebo
UK

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."
- Albert Einstein (1879-1955)
 
I have it in
Group Header #2a: BillStatment.ID A(Section 12)

and all my report info is now been moved to

Group Header #2b.: BillStatment.ID A(Section 8)
 
If the sub report is linked correctly, then what should happen is :

Group Header #2a - Sub Report runs, linked by the customer number only information for that customer should appear in the subreport. The sub report formula should be placed in the sub report footer, thus setting the value of myTotal to the sum({Balance}) for the single customer.

Group Header #2b - Reference to the value of myTotal.

I don't see why this wouldn't work correctly....

On top of that I've got to leave early today (next 15 mins), but hopfully someone else can pick up where I've left off......

Reebo
UK

"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former."
- Albert Einstein (1879-1955)
 
I have placed the forumal in the report subreport footer, still coming in zero, perhaps I have done something wrong. Well lets see what happens, I will try to go back to an older version and try to rebuild all the steps you gave me again
 
Do you have to use "shared variables"??

the reason I ask is that you don't seem to do anything with the subreport result other than display it.

If you are just displaying the result then

simply end the subreport with a formula in the report footer

//@result
WhilePrintingRecords;
NumberVar myTotal;

"Total Balance: $" + Totext(myTotal,2);

suppress all other sections of the subreport so the report footer is only showing.

Otherwise, if you need the result to use the result for other purposes in the main report then you must re-initialize the value of myTotal in the subreport...or the main report.

the subreport needs to be in the section immediatly prior to the one where the resulting shared value is used. If you are resetting the shared value to zero. this must be done in a section before the subreport is reused...a group footer is fine.


Jim Broadbent

The quality of the answer is directly proportional to the quality of the problem statement!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top