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

Passing parameter from VB

Status
Not open for further replies.

smil3y

IS-IT--Management
Jan 8, 2004
79
AU
Hi,
I am still using CR8.5 and VB 6. I am passing a date from VB to CR using the entry:

TaskReport.parameterfields.getItemByName ("SelectDate")
.AddCurrentItem dTaskDate

Taskreport is my report object and SelectDate is the parameter within the report while dTaskDate is the date I am passing. This all works perfectly for the MainReport.

My Taskreport has 3 subreports that also require the selectDate to be passed to them. Is it possible to pass the dTaskDate variable to the subreports within TaskReport, if so what VB code do I use.

many thanks
 
If the subreports are linked to the main report by the SelectDate parameter, then you won't need to pass the parameter to the subreports from VB.

If they're not linked, then you'd need to get to each SubreportObject by looping through the report's Sections collection, and looking for the subreports in each section. Once you find a subreport, you would set the parameter value. Something like this:
Code:
Dim crxSubreportObj As CRAXDRT.SubreportObject
Dim crxSubreport As CRAXDRT.Report
Dim crxSection = CRAXDRT.Section
Dim crxReportObjects as CRAXDRT.ReportObjects
Dim crxReportObject As Object

For Each crxSection In TaskReport.Sections
  Set crxReportObjects = crxSection.ReportObjects
  For Each crxReportObject In crxReportObject
    If crxReportObject.Kind = crSubreportObject Then
      Set crxSubreportObj = crxReportObject
      Set crxSubreport = crxSubreportObj.OpenSubreport
      crxSubreport.ParameterFields.GetItemByName ("SelectDate").AddCurrentItem dTaskDate
    End If
  Next crxReportObject 
Next crxSection
-dave
 
Many thanks.
Boy I did not think this would be so complicated and I am not sure if I fully understand exactly the steps you are advising.

I think there was one typo:

For Each crxReportObject In crxReportObject
should be - For Each crxReportObject In crxReportObjects

It all seemed to work as in cycled through and passed the parameters, but I still get the dialogue box popping up to request the date for the 4 parameters.

Is there anywhere that I can get an explanation of what this code is doing? I sort of understand but very limited and I would like to understand better?

Why do I still get asked to provide the parameters. They seem to get passed via VB.
 
To keep the parameter window from showing, put this in your code just before you view/print the report:
[tt]
TaskReport.EnableParameterPrompting = False
[/tt]
The code in the previous post is cycling through each Section of the report. It looks at each object in the Section to determine whether it's a subreport. Once a subreport is found, it's opened like a regular report. Then, you can interact with it the same way you would a "main" report. In the above case, after finding the subreports, you're opening them, and setting the "SelectDate" parameter.

But as I also stated in the previous post, if the subreports are linked to the main report by the SelectDate parameter, you wouldn't have to do all of this code wrangling.

-dave
 
Many thanks.

The main report has a due date field and each of the three subreports also has a due date field. It is this due date that I am passing as the parameter.

I created the parameter in the main report and thought I may be able to link to the due dates in the sub reports. I selected CHANGE SUB REPORT LINKS and then selected my main report parameter to try and link on. I can select the parameter, move it to the 'Field to Link To' but when I try to 'Select data in subreport based on field' there are no fields to select. I thought this may because of the fact that they are different due dates field names.

I agree this would be preferred way - any ideas?

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top