cancel
Showing results for 
Search instead for 
Did you mean: 

Null subreport

Former Member
0 Kudos

I have a report with 2 not linked subreports. I am trying to open a subreport to pass a dataset and parameters but when I open the first subreport it is null, why? this is the code:

Reports.MoneyReceipt moneyReceiptRDC = new Reports.MoneyReceipt(); // A wrapper to my report.

moneyReceiptRDC.Load();

moneyReceiptRDC.SetDataSource( document.Tables[ 0 ] );

moneyReceiptRDC.SetParameterValue( "pIsPreprintedForm", isPreprinted );

ReportDocument subReport1 = moneyReceiptRDC.OpenSubreport( "Subreport1" ); // After this, subReport1 is still null, WHY?

ReportDocument subReport2 = moneyReceiptRDC.OpenSubreport( "Subreport2" );

subReport1.SetDataSource( document.Tables[ 1 ] );

subReport2.SetDataSource( document.Tables[ 1 ] );

subReport1.ParameterFields.Clear();

subReport1.ParameterFields[ 0 ].CurrentValues.AddValue( documentCurrency );

subReport2.ParameterFields.Clear();

subReport2.ParameterFields[ 0 ].CurrentValues.AddValue( documentCurrency );

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

Probably because as far as the report is concerned, it's not getting the right data. You do not mention what version of CR or .NET, but have a look at the [Troubleshooting Issues with VS .NET Datasets and Crystal Reports|https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/13270] [original link is broken] [original link is broken] [original link is broken]; blog. It should be bale to help you figure out what's going on.

Ludek

Answers (2)

Answers (2)

Former Member
0 Kudos

I did a mistake, "Subreport1" is the name of the object within the main report not the name of the subreport itself (right name is "Subreport1.rpt"). Afther fixing this I did another mistake: passing parameters to a subreport is not possible through the subreport itself but through parameter's collection of the main report. Here is the right code:

// 1. Instance, load and clean of the report.

Reports.MoneyReceipt moneyReceiptRDC = new Reports.MoneyReceipt();

moneyReceiptRDC.Load();

moneyReceiptRDC.Refresh(); // I added this to clean any saved data in the report, if any.

// 2. Opening subreports.

ReportDocument subReport1 = moneyReceiptRDC.OpenSubreport( "Subreport1.rpt" ); // Using the right subreport name.

ReportDocument subReport2 = moneyReceiptRDC.OpenSubreport( "Subreport2.rpt" );

// 3. Setting the datasource to report and subreports.

moneyReceiptRDC.SetDataSource( document.Tables[ 0 ] );

subReport1.SetDataSource( document.Tables[ 1 ] );

subReport2.SetDataSource( document.Tables[ 1 ] );

// 4. Setting parameters.

// Parameter 1 and 2 are parameters in Suberport1.rpt and Subreport2.rpt respectively and have the same

// name "pReceiptCurrencySymbol". In this case don't use parameter's names but the parameter's index.

moneyReceiptRDC.SetParameterValue( 0, isPreprinted ); // pIsPreprintedForm

moneyReceiptRDC.SetParameterValue( 1, documentCurrency ); // pReceiptCurrencySymbol

moneyReceiptRDC.SetParameterValue( 2, documentCurrency ); // pReceiptCurrencySymbol

// 5. Ready to print.

moneyReceiptRDC.PrintToPrinter( copies, false, 1, 1 );

// 6. HAPPY END THANK YOU LUDEK FOR YOUR PATIENT AND HELP.

former_member183750
Active Contributor
0 Kudos

Great to hear it's working. But, pls, pls do go to a supported version of CR. I've seen CR XI r2 work in dev, and then not once it gets distributed. Or it works on some distributed computers and not others, even though the computers are off of the same image. I've seen where the app works for a while, then mysteriously stops working. So, just a bit of a warning....

Ludek

Former Member
0 Kudos

I am using CR XI R2, VS 2008, the datasource is a dataset with 2 tables, Table1 is the datasource for main report, Table2 is the datasource for Subreport1 and Subreport2, they are not linked, when Subreport1 is shown Subreport2 is not depending on a field value in Table1. I am not sure if I am using the right order to access the objects, Subrerport1 is null after loading the main report so when I assign the DataSource I get the error: "Object reference not set to an instance of an object." Am I missing something? I am sure the DataSet match the table and field definitions of the report.

former_member183750
Active Contributor
0 Kudos

CR XI r2 is not supported with .NET 2008. Only the bundled version of CR (10.5) - Crystal Reports Basic for Visual Studio 2008 and Crystal Reports 2008 (12.1) is supported in .NET 2008.

See the supported platforms for CR XI r2:

https://www.sdn.sap.com/irj/boc/index?rid=/library/uuid/f0157c8a-901e-2b10-49b1-8ac0d88cca18&overrid...

Also, see the [Crystal Reports assembly versions and Visual Studio .NET|https://wiki.sdn.sap.com/wiki/display/BOBJ/CrystalReportsassemblyversionsandVisualStudio+.NET] wiki.

Ludek