How to pass parameters value to subreports in crystal report ?

Hi,

I have a main report which accept one parameter and populate report data. In the same report I have subreport which accept the same paramter for detail. I am using SQL stored procedure in my reports and I am working in VB6. Here is my code:

Private Sub Command1_Click()
 
    With CrystalReport1
        .ReportFileName = "C:\IMT\REPORTS\KHReceipt.rpt"
        .RetrieveStoredProcParams
        T = LTrim(RTrim(txtMessageNo.Text))
        .StoredProcParam(0) = T
      .Action = 1
    End With
End Sub

this routine is working fine if there is no subreport but when I add my subreport for detail, it prompt for subreport paramater value. So my question is how can I pass parameter value to my subreport?
Thanks
khalidsuhailAsked:
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.

khalidsuhailAuthor Commented:
I found some link in business decesion  forum but they are not working so give me sample code.
0

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
Antagony1960Commented:
You need to use a shared variable. Create a new formula in the main report with the following in it:

Shared stringVar sText := ({?pMyParam});

Substitute pMyParam for your own parameter, of course. Place the formula in a section above the subreport and suppress it so that it doesn't display.

Now, in your sub report, remove the parameter field and use the shared variable wherever you need it. For example, if you just needed to display the value, you would create a formula like this:

Shared stringVar sText;
sText;
0
khalidsuhailAuthor Commented:
Hi Antagony:
How can I remove my parameter? This paramter is a part of my Stored Procedure. And my stored procedure need it to populate data. When I desgined my subreport I refered my stored procedure as database source. Is there any other solution?
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

khalidsuhailAuthor Commented:
Here is my solution which i found is great:
You have to get subreport name first and then pass its stored procedure parameter value and then changed the control to main report with .SubreportToChange = "" 
This will get control back to main report.

Private Sub Command1_Click()
   
    With CrystalReport1
        .ReportFileName = "C:\IMT\REPORTS\KHReceipt.rpt"
           .RetrieveStoredProcParams
        t = LTrim(RTrim(txtMessageNo.Text))
            .SubreportToChange = .GetNthSubreportName(0)
.StoredProcParam(0) = t
.SubreportToChange = "" 
        .StoredProcParam(0) = t
       
       .Action = 1
       
    End With
   
   End Sub
0
Antagony1960Commented:
Ah, I'm glad you've sorted it out. I've always tended to avoid using parameters in sub reports, preferring shared variables.

One minor tip on your code, you don't need to use LTrim & RTrim like you've done; just use:
t =Trim(txtMessageNo.Text)
0
mlmccCommented:
You can't use a shared variable.  They are evaluated after the stored procedure is run.

You perhaps could have linked the report on the parameter.

mlmcc
0
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
Visual Basic Classic

From novice to tech pro — start learning today.