Crystal Report Sub Report Import

mgmhicks
mgmhicks used Ask the Experts™
on
I have 2 reports that each are using the same sub report.   However on one main report when I right click, I dont have the option to reimport the sub.  On the other one I do.  The oine that works well in vb code is the one that doesnt have the option to reimport sub report.  What causes this to be the difference?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009

Commented:
I suspect you wrote the subreport as part of the first report, and saved it to then import into the other one.

Author

Commented:
Yea, I guess thats what ended up happening.  Is there a way to  fix the situation.  Does it even matter.  I can tell in code using vb when I tell it to open the subreport, on the original I just tell it leasingbonus3 on the other report I have to say leasingbonus3.rpt.

Top Expert 2009

Commented:
Why are you opening the subreport in vb? Are you resetting the database logins?
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Author

Commented:
YES,
Top Expert 2009
Commented:
You can do it in a more generic loop in vb which simply goes through each section and finds the subreports and resets them.

Attached is the Visual C code,
foreach (CrystalDecisions.CrystalReports.Engine.Table table in _reportDocument.Database.Tables)
			{
                AssignTableConnection(table, connection);
  
			}

			// Now loop through all the sections and its objects to do the same for the subreports
			//
			foreach (CrystalDecisions.CrystalReports.Engine.Section section in _reportDocument.ReportDefinition.Sections)
			{
				// In each section we need to loop through all the reporting objects
				foreach (CrystalDecisions.CrystalReports.Engine.ReportObject reportObject in section.ReportObjects)
				{
					if (reportObject.Kind == ReportObjectKind.SubreportObject)
					{
						SubreportObject subReport = (SubreportObject)reportObject;
						ReportDocument  subDocument = subReport.OpenSubreport(subReport.SubreportName);

						foreach (CrystalDecisions.CrystalReports.Engine.Table table in subDocument.Database.Tables)
						{
							AssignTableConnection(table, connection);
						}
					}
				}
			}

Open in new window

Author

Commented:
what he does here probably works, but more compersome then I was looking for.  Ended up doing it in formula fields.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial