views:

27

answers:

3

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.

A: 

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")

dotjoe
HiThanks 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.
Richard
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.
dotjoe
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?
Richard
A: 

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?

Eric Towers
Using this method gives me an IndexOutOfRangeException
Richard
Having to do this without access to Crystal Reports module (i.e. from Express edition), so the corrected above is probably only close.
Eric Towers
A: 

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.

Richard