Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

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

Like the title say...
Thanks in advance
0
CaptainKirk
Asked:
CaptainKirk
1 Solution
 
AConoverCommented:
Scenario 1:

You could make the title a parameter field that the user would have to fill in when the report is run:
1.  In Field Explorer create a new parameter field.
2.  Give it a name, prompting text and select string for value type.
3.  Place this field in the page header or report header (where ever you want the title to display).
4.  You can modify like any other field for fonts, etc.

Now when the report is run, the user will be prompted to type in a title.

Scenario 2:

If you only wanted a choice of specific titles to choose from.  Create the parameter field like above except in options click on the default values button and add values for the user to select from (ex. a b and c).  This will create a drop down box for user. Then create a formula for choices like below:

if {parameter field you created} = "a" then "Report title one" else
if {parameter field you created} = "b" then "Report title two" else
if {parameter field you created} = "c" then "Report title three"

Now put this formula where you want your title to be.  When the user runs the report, the parameter field will prompt them to select a, b or c and the formula will display the correct title.

Hope this helps.

AC

0
 
dbirdmanCommented:
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.
0
 
GarfyCommented:
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"

0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now