Link to home
Start Free TrialLog in
Avatar of nomar2
nomar2

asked on

Problems with subreports in Crystal reports in VB.Net

I creating crystal reports in in VB.net  I have a report which I use the following code to fire the report..


       cr.DataSourceConnections.Item(0).SetConnection(lcServerName, lcDatabase, lbTrusted)
'the variables are all determined beforehand
        cr.SetDatabaseLogon("sa", "sa")
        cr.SetParameterValue("iDepotID", lDepotID)
        cr.SetParameterValue("iRptDate", lReportDate)
         cr.PrintToPrinter(1, True, 0, 0)

the problem is if I add a subreport from the same database I get a error message saying "invalid table number"

The name of subreport is "rpt_DayEndDonation"  this is what I was doing ..


     cr.DataSourceConnections.Item(0).SetConnection(lcServerName, lcDatabase, lbTrusted)
'the variables are all determined beforehand
        cr.SetDatabaseLogon("sa", "sa")
        cr.SetParameterValue("iDepotID", lDepotID)
        cr.SetParameterValue("iRptDate", lReportDate)
 cr.OpenSubreport("rpt_DayEndDonation").DataSourceConnections.Item(0).SetConnection(lcServerName, lcDatabase, lbTrusted)
        cr.OpenSubreport("rpt_DayEndDonation").SetDatabaseLogon("sa", "sa")
        cr.OpenSubreport("rpt_DayEndDonation").SetParameterValue("iDepotID1", lDepotID)
        cr.OpenSubreport("rpt_DayEndDonation").SetParameterValue("iRptDate1", lReportDate)
        cr.PrintToPrinter(1, True, 0, 0)


But this doesn't work..so how do I pass the database connection to the subreport and how do i pass parameter info to the subreport..

I am totally lost...
Avatar of RajendraDewani
RajendraDewani

Here is the sample code

Report.SetDatabaseLogon(rptLogin, rptPassword, rptServer, rptDatabase);
ReportDocument subreport;
subreport = Report.OpenSubreport("rptStudentAveragesSub.rpt");
subreport.SetDatabaseLogon(rptLogin, rptPassword, rptServer, rptDatabase);

With Regards
Rajendra Dewani
Avatar of nomar2

ASKER

Dim cr as New rpt_DayEnd

    cr.DataSourceConnections.Item(0).SetConnection(lcServerName, lcDatabase, lbTrusted)
     cr.SetDatabaseLogon("sa", "sa")
     cr.SetParameterValue("iDepotID", lDepotID)
     cr.SetParameterValue("iRptDate", lReportDate)

This works up to here...
The name of the subreport is "rpt_DayEnd1"
Do I delcare a variable for the subreport ?? I am using VB.Net
 
Avatar of Mike McCracken
Just open the subreport as in the suggestion above and repeat your code using the subreport object.

mlcmc
Avatar of nomar2

ASKER

      cr.DataSourceConnections.Item(0).SetConnection(lcServerName, lcDatabase, lbTrusted)
        cr.SetDatabaseLogon("sa", "sa")
       'main report
        cr.SetParameterValue("iDepotID", lDepotID)
        cr.SetParameterValue("iRptDate", lReportDate)
       'subreports
        cr.SetParameterValue("iDepotID", lDepotID, "rpt_DonationsDayEnd")
        cr.SetParameterValue("iRptDate", lReportDate, "rpt_DonationsDayEnd")
        cr.SetParameterValue("iDepotID", lDepotID, "rpt_CreditsDayEnd")
        cr.SetParameterValue("iRptDate", lReportDate, "rpt_CreditsDayEnd")
        cr.SetParameterValue("iDepotID", lDepotID, "rpt_FloatDayEnd")
        cr.SetParameterValue("iRptDate", lReportDate, "rpt_FloatDayEnd")
        cr.PrintToPrinter(1, True, 0, 0)

This works the problem is if one of my subreports has one than 1 table (and they are joined correctly) I get the error "INVALID TABLE NUMBER"...

Any ideas?? You help so far has been most helpful!!
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial