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!

Location for On-Demand Subreports 1

Status
Not open for further replies.

redmondson92

Programmer
Dec 7, 2001
11
US
Using: Report Designer 8.5
Situation: created Active X control that is integrated into a C++ app, reports are designed using ODBC to SQL Server 7.0 and reference a stored procedure. My active x control sets the location for the report based on the DSN and database name that it is connecting to (info provided by app).

Problem: many of my reports use on-demand subreports - I can't (as far as I know) programtically set the location for their datasource when I drill down on them. Thus, if either the database name or DSN name is different than what I designed it with, no data is returned after drilldown.

1) does anyone know of a way to set the table location for on-demand subreports?
2) is there a way to use aliasing to help here?
3) is there a way to link the data source for the master report to the subreport?

Any ideas appreciated.
 
Have you tried:
CrystalReport1.SubreportToChange = "yoursubreport"

and then using the connect or LogOnInfo command? Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Hi Ken,

I don't quite follow your suggestion. I'm not familiar with "SubReportToChange". Is it a property of the report object? Or is this the name of the subreport? I don't see it in my object browser of help. I am using craxdrt.dll and crviewer.dll (8.5 for both). Can you explain this a little more if you have time? Thanks...

-Rob
 
I didn't realize you were using the RDC, I saw Active X and thought you were using the OCX.

In the RDC you need to create another report variable for the subreport, then use the OpenSubreport command to assign the subreport to the variable. Then the subreport has exposed properties just like the main report. Sorry, I don't have a code example for this, but someone else might. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Thanks, I thought about that, but since they are on-demand, I am letting the viewer open the subreport up into a separate tab during the DrillOnSubreport event in the viewer. Will setting the subreport object into a new report object affect what happens when the user drills down on the subreport link? I will give it a try - Thanks again-
 
I have never done it, so let us know if it works. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Sample code to open up the sub-report and logon. Maybe I should make this an FAQ.

Dim Report As CRAXDRT.Report
Dim SubReport As CRAXDRT.Report
Dim App As CRAXDRT.Application
Dim Sections As CRAXDRT.Sections
Dim Section As CRAXDRT.Section
Dim RepObjs As CRAXDRT.ReportObjects
Dim SubReportObj As CRAXDRT.SubreportObject
Dim n As Integer
Dim i As Integer
Dim j As Integer

Set App = New CRAXDRT.Application
Set Report = App.OpenReport("your.rpt")

For n = 1 To Report.Database.Tables.Count
Report.Database.Tables(n).SetLogOnInfo "server", "dbname", "user", "pass"
Next n

Set Sections = Report.Sections
For n = 1 To Sections.Count
Set Section = Sections.Item(n)
Set RepObjs = Section.ReportObjects
For i = 1 To RepObjs.Count
If RepObjs.Item(i).Kind = crSubreportObject Then
Set SubReportObj = RepObjs.Item(i)
Set SubReport = SubReportObj.OpenSubreport
For j = 1 To SubReport.Database.Tables.Count
SubReport.Database.Tables(j).SetLogOnInfo "server", "db", "username", "pass"
Next j
End If
Next i
Next n
 
Thanks Balves - just to clarify, will this apply to on-demand subreports as well?
 
Follow up -

This worked like a charm with the on-demand subreports. Thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top