Hi All
I want to get the following working, please could someone advise...
Dim rpt As ReportDocument
If (Exists(rpt.ReportDefinition.ReportObjects("crlTitle"))) Then
txtTitle = CType(rpt.ReportDefinition.ReportObjects("crlTitle"), TextObject)
txtTitle.Color = mainColour
txttitle.Text = "Report Title"
End If
Any help much appreciated.
From stackoverflow
-
I've never done anything like that...I'm not sure if it's possible. What will work for sure though is to use a parameter to control the report title. Simply create a parameter and then
rpt.SetParamterValue("title", "Some Title")
Richard : Hi Thanks for your response. and yes, if I was creating all of my reports from scratch then I could do it that way, my reason for asking about doing this in code is that there are already 200+ reports set up and so it is less time consuming executing this through vb code.dotjoe : I see...in order to dynamically change the report, you might need to save it after changing that field and then run it. Can you try a `rpt.SaveAs("test.rpt", RptFileFormat)` and then open it and see if the title was actually changed.Richard : The problem I have Joe is that the object may not exist on the report so this would throw an error and the report would not load. You get where Im coming from? -
Since you've identified the problem as "Exists is undefined". Addressing that problem is more straightforward. Try replacing the "Exists" line with:
If (rpt.ReportDefinition.ReportObjects.Contains("crlTitle")) Then
Were there any other problems?
Richard : Using this method gives me an IndexOutOfRangeExceptionEric Towers : Having to do this without access to Crystal Reports module (i.e. from Express edition), so the corrected above is probably only close. -
Here is my solution:
Dim rpt as ReportDocument Dim rptTextObject as TextObject = nothing Dim mainColour As Color = Color.Green Try If (rpt.ReportDefinition.ReportObjects("crlTitle") IsNot Nothing) Then rptTextObject = CType(rpt.ReportDefinition.ReportObjects("crlTitle"), TextObject) rptTextObject.Color = mainColour rptTextObject.Text = "Report Title" End If Catch End Try
I do this for each Object on the report that I want to either set text or set colour.
0 comments:
Post a Comment