?
Solved

How to pass parameters value to subreports in crystal report ?

Posted on 2008-11-08
6
Medium Priority
?
1,873 Views
Last Modified: 2013-11-26
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
0
Comment
Question by:khalidsuhail
  • 3
  • 2
6 Comments
 

Accepted Solution

by:
khalidsuhail earned 0 total points
ID: 22914835
I found some link in business decesion  forum but they are not working so give me sample code.
0
 
LVL 11

Assisted Solution

by:Antagony1960
Antagony1960 earned 400 total points
ID: 22915623
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
 

Author Comment

by:khalidsuhail
ID: 22917082
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:khalidsuhail
ID: 22917841
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
 
LVL 11

Expert Comment

by:Antagony1960
ID: 22918041
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 22918909
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month17 days, 3 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question