×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

setting parameter fields of sub-reports in vb

setting parameter fields of sub-reports in vb

setting parameter fields of sub-reports in vb

(OP)
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

RE: setting parameter fields of sub-reports in vb

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

RE: setting parameter fields of sub-reports in vb

(OP)
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?


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

RE: setting parameter fields of sub-reports in vb

(OP)
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

RE: setting parameter fields of sub-reports in vb

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

RE: setting parameter fields of sub-reports in vb

(OP)
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

RE: setting parameter fields of sub-reports in vb

(OP)
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,

RE: setting parameter fields of sub-reports in vb

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.

RE: setting parameter fields of sub-reports in vb

(OP)
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?

RE: setting parameter fields of sub-reports in vb

At work, my customer is stuck on Crystal V7.  I have V8.5 at home so I could look at it later.

RE: setting parameter fields of sub-reports in vb

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.

RE: setting parameter fields of sub-reports in vb

(OP)
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

RE: setting parameter fields of sub-reports in vb

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close