Link to home
Start Free TrialLog in
Avatar of CaptainKirk
CaptainKirk

asked on

Is there any way to change the report title at runtime?

Like the title say...
Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of AConover
AConover

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dbirdman
dbirdman

Here's an example to add the title at runtime with code.  you can do this after the user selects the title, or set the title without user intervention.  This requires that a Parameter Field is set up in the Crystal Report, as AConover Stated.  This particular code is untested, though should work:

Dim crApp As CRAXDRT.Application
Dim crRpt As CRAXDRT.Report
Dim crSection As CRAXDRT.Section
Dim ImgObject As OLEObject
Dim strRptName As String
Dim strImgName As String
Dim Params As CRAXDRT.ParameterFields
Dim HeaderParam As CRAXDRT.ParamFieldDefinition

Set crApp = New CRAXDRT.Application

strRptName = "C:\MyReport.rpt"

'Open Report
If IsObject(crRpt) Then
    Set crRpt = Nothing
End If

Set crRpt = crApp.OpenReport(strRptName, 1)

set Params = oRpt.Parameterfields
set HeaderParam = Params.Item(1)
         
'Parameter 12 in SetCurrentValue tags parameter as a String
Call HeaderParam.SetCurrentValue (CStr(HeaderText), 12)

crRpt.MorePrintEngineErrorMessages = False
crRpt.EnableParameterPrompting = False
crRpt.DiscardSavedData

' Set the viewer's report source to the Report object
CRViewer1.ReportSource = crRpt
CRViewer1.ViewReport


Hope this helps.
why use all the parameters.....  in VB, the Crystal Report control has a property, Report Title.  If you have placed the report title on your report and want to change it at runtime, just use the following syntax

MyCrystalReportControl.ReportTitle = "My Title"