Print Page | Close Window

change text field in subreport

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=5802
Printed Date: 16 May 2024 at 6:00am


Topic: change text field in subreport
Posted By: Enzyme80
Subject: change text field in subreport
Date Posted: 17 Mar 2009 at 7:46am
Wondering if it is possilbe to change the text of a text object at runtime that is in a subreport.
 
I know you can do this in the main report by something like
 
dim strRCSZ as string
Dim rptTxtGroup As TextObject    
strRCSZ = "my info"
rptTxtGroup = rpt.ReportDefinition.ReportObjects.Item("Text1")
rptTxtGroup.Text = strRCSZ

Basically I want to do the exact same thing but for the subreport, i just can't figure it out.




Replies:
Posted By: hilfy
Date Posted: 17 Mar 2009 at 1:15pm
You have to find the subreport and get to it's fields.  It's like setting the table logins for subreports in code.
 
Assuming you're using the ReportDocument object model, I think it will look something like this:
Sections sections = reportDocument.ReportDefinition.Sections;
foreach (Section section in sections)
{
  ReportObjects reportObjects = section.ReportObjects;
  foreach (ReportObject reportObject in reportObjects)
  {
    if (reportObject.Kind == ReportObjectKind.SubreportObject)
    {
      SubreportObject subreportObject = (SubreportObject)reportObject;
      ReportDocument subReportDocument =
        subreportObject.OpenSubreport(subreportObject.SubreportName);
      <add code to set the text object>          
    }
  }
}
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: Enzyme80
Date Posted: 18 Mar 2009 at 12:10pm
Hmm... well apprerantly i used to be better at translating code from c# to vb.net. 
I am using the reportdocument object model but it does not have the reportdefinition in it.  
I will keep trying to convert the code. hopefully it will lead me where I need.


Posted By: Enzyme80
Date Posted: 18 Mar 2009 at 12:36pm

here is the VB version of it.  sorry for the long formatting, I just copied and pasted the code from VS 2005.

Dim rpt As ReportDocument = New ReportDocument
Dim rSections As Sections
Dim rSection As Section
Dim sReportObjects As ReportObjects
Dim sReportObject As ReportObject
Dim subReportObject As SubreportObject
Dim subReportDoc As ReportDocument
Dim rptTxtGroup As TextObject
 
rSections = rpt.ReportDefinition.Sections
For Each rSection In rSections
     sReportObjects = rSection.ReportObjects
     For Each sReportObject In sReportObjects
          If sReportObject.Kind = ReportObjectKind.SubreportObject Then
               subReportObject = sReportObject
               subReportDoc = subReportObject.OpenSubreport(subReportObject.SubreportName)
               rptTxtGroup = subReportDoc.ReportDefinition.ReportObjects.Item("Text3")
               rptTxtGroup.Text = "Test"
          End If
     Next
Next
 



Print Page | Close Window