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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

setting parameter fields of sub-reports in vb

Status
Not open for further replies.

Delboy14

Programmer
Jun 21, 2001
213
GB
Crystal Reports 8.5, Automation Server, VB 6

I have a main report which is made up of many sub reports, within vb I have a button which generates the report in teh report viewer, I can specify the paramater field for the main report using the code:
Report.ParameterFields("NumPatientsandConsults").SetCurrentValue ("BRAD02")

I am having difficulty setting the paramater values within the sub reports, the updating the main report, I am getting an error "Subscript out of range".

Is there a way to produce code for the Crystal equivalent of
Refresh Report Data, Prompt for new paramter values, then fill in the paramater values. I do not want the prompt to be displayed I would like to fill the paramaters in using code. and example of one of my sub reports is Page6 and the paramater is PracticeID={BRAD01}. thankyou for any help in advance
 
I believe you want to do something like this. If you have multiple sub-reports and want to set different parameters for different sub-reports, you'll need to figure out which sub-report you're working with in the FOR loop.
-----------------------------------------------------------

Dim Report As New CrystalReport1 ' your report
Dim crSecs As CRAXDRT.Sections
Dim crSec As CRAXDRT.Section
Dim crRepObjs As CRAXDRT.ReportObjects
Dim crSubRepObj As CRAXDRT.SubreportObject
Dim crSubReport As CRAXDRT.Report
Dim i As Integer

Set crSecs = Report.Sections
For i = 1 To crSecs.Count
Set crSec = crSecs.Item(i)
Set crRepObjs = crSec.ReportObjects
For X = 1 To crRepObjs.Count
If crRepObjs.Item(X).Kind = crSubreportObject Then
Set crSubReport = Report.OpenSubreport(crRepObjs.Item(X).SubreportName)

crSubReport.ParameterFields ....
End If
Next
Next
 
Crystal Reports 8.5, Automation Server, VB6

When using this code I now get a type mismatch error on the line: Set crSecs = Report.Sections
do you have any ideas?

Code:
Private Sub GenerateReport_Click()
Dim PracticeID As String
Dim crSecs As CRAXDRT.Sections 
Dim crSec As CRAXDRT.Section 
Dim crRepObjs As CRAXDRT.ReportObjects 
Dim crSubRepObj As CRAXDRT.SubreportObject 
Dim crSubReport As CRAXDRT.Report 
Dim i As Integer 'tek-tips code


PracticeID = PracticeSelection.PracticeID
Set App = CreateObject("Crystal.CRPE.Application")
Set Report = App.OpenReport("c:\Derek\Reports\Database\MainReport.rpt")
Set crSecs = Report.Sections 
For i = 1 To crSecs.Count 
  Set crSec = crSecs.Item(i) 
  Set crRepObjs = crSec.ReportObjects 
    For X = 1 To crRepObjs.Count 
      If crRepObjs.Item(X).Kind = crSubreportObject Then 
          Set crSubReport = Report.OpenSubreport(crRepObjs.Item(X).SubreportName) 

          crSubReport.ParameterFields("PracticeID").SetCurrentValue (PracticeID) 
      End If 
    Next 
Next 


Report.PrintWindowOptions.CanDrillDown = True
Report.ParameterFields("NumPatientsandConsults").SetCurrentValue (PracticeID)

Report.Preview


End Sub
 
I tried your code but could not get it to work, does your code use the automation server? that is what I am using, it does not seem to recognise some of the commands that you mentioned. I have tried the code below and it does up date the sub report but, not in the main report, is there away to enter the parameter for the sub report then re-import it into the main report? would this solve my problem?


Dim App As CRPEAuto.Application
Dim Report As CRPEAuto.Report
Dim crSubReport1 As CRPEAuto.Report

Private Sub GenerateReport_Click()
Dim PracticeID As String
PracticeID = PracticeSelection.PracticeID

Set App = CreateObject("Crystal.CRPE.Application")
Set Report = App.OpenReport("c:\Derek\Reports\Database\MainReport.rpt")
Set SubReport1 = App.OpenReport("c:\Derek\Reports\Database\Page14-Graph.rpt")



Report.PrintWindowOptions.CanDrillDown = True
Report.ParameterFields("NumPatientsandConsults").SetCurrentValue (PracticeID)


SubReport1.ParameterFields("PracticeID").SetCurrentValue (PracticeID)

SubReport1.Preview
Report.Preview


End Sub
 
We were using the RDC.

So this statement:

Set App = CreateObject("Crystal.CRPE.Application")


would be:

Dim App As CRAXDRT.Application

Set App = New CRAXDRT.Application
 
thanks, but do you know how to solve my problem, of updating the subreport, and showing these change in the main report (which contains the subreport), thankyou for your help
 
I have even tried referencing the parameter directly i.e.
Report.ParameterFields("PracticeID (6.Working.rpt)").SetCurrentValue (PracticeID), but I get an error subscript out of range,

 
Perhaps I don't understand your problem too well, but why not pass the parameter initially to the main report, and then link the subreport to the main report by the same parameter / field.

 
I think you do understand my problem, and since I am using CRv8.5 KenHamady advised me that there is a bug in this version of Crystal Reports and to add a paramater to the main report which links to the parameter in the subreport you have to, right click on the subreport object (in the main report I pressume) and select change sub report links. Then, move it over from the main report, ken said this should create a parameter to match in the subreport, It should also add a rule in the subreport selection formula, Once it adds this parameter, you can use it instead of your old parameter in the subreport.

The problem is this did not update my subreport, there was no paramater or selection rule added? Do you have CRv8.5, how would you do this task?
 
At work, my customer is stuck on Crystal V7. I have V8.5 at home so I could look at it later.
 
You can create a parameter in the main report, say p_mainrpt. If you don't use this parameter in the main report's selection formula, you must place it somewhere on the report anyway. Otherwise, Crystal won't prompt for a value.

You can then create a sub-report and create the query for the sub-report. Going back to the main report, you can create the main/subreport link by selecting the p_mainrpt field and linking it to a field in the subreport.

What you cannot do, and I'm not sure you need to, is create a parameter in the subreport, say p_subrpt1, and try to link the main parameter to the subreport parameter.
 
sorry, but how do you view the tables from the sub report.
I have named the parameter, in the Edit parameter field and then went to the set default values and the only tables I can see are the ones in the main report, how can I link it to field in the sub report
 
If you create a parameter in the main report, you can link it to a field in the subreport via Change Subreport Links. You can pick the p_main parameter and link it to a similarly typed field in any table of the subreport.

You cannot, however, set default values for the parameter in the main report to some values of a table in the subreport.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top