SAP Knowledge Base Article - Public

1214187 - Modifying report formula fields at runtime using the Crystal Reports .NET SDK

Symptom

  • Crystal Reports .NET custom application.
  • How to modify/change a formula field in the report? 

Resolution

To modify two formula named 'TenTimes' and 'ThreeTimes', use the following code:

'import namespaces in general section 
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

'Generic code for setting formulas

Dim crReport As New CrystalReport1()
Dim crFormulaFieldDefinitions As FormulaFieldDefinitions
Dim crFormulaFieldDefinition As FormulaFieldDefinition
Dim LoopFormula As Integer
Dim FormulaName As String

crFormulaFieldDefinitions = crReport.DataDefinition.FormulaFields

'Loop through the formula fields collection
For LoopFormula = 0 To crFormulaFieldDefinitions.Count - 1
 'Retrieve the current formula in the collection 
 crFormulaFieldDefinition = crFormulaFieldDefinitions.Item(LoopFormula)
 FormulaName = crFormulaFieldDefinition.Name
 'Set the formula test by by formula name
 Select Case FormulaName
  Case "TenTimes"
  crFormulaFieldDefinition.Text = "{Customer.Last Year's Sales} * 10"
  Case "ThreeTimes"
  crFormulaFieldDefinition.Text = "{Customer.Last Year's Sales} * 3"
 End Select
Next
CrystalReportViewer1.ReportSource = crReport

 

Keywords

FORMULA CHANGE REPLACE DOTNET VB.NET FORMULAS .NET Crystal Reports for Visual Studio Formula Fields Modify at runtime , c2010287 , KBA , BI-DEV-NET , BI Software Development Kits (SDKs) - .NET or Other , How To

Product

SAP Crystal Reports, developer version for Microsoft Visual Studio ; SAP Crystal Reports, version for Visual Studio .NET 2008