VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Add Graph,Groups,Total in Crystal Report at RunTime

by Naeem Akram (3 Submissions)
Category: Custom Controls/Forms/Menus
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 5th November 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Add Graph,Groups,Total in Crystal Report at RunTime

API Declarations


'You can add Crystal Report Viewer Control from Add component.
'Add Crystal Report 8.0 Active x Designer Run Time Library,Crystal Report 8.0 Active x Designer Design Time Library (Internal) and Crystal Report Viewer Control.After adding Component and Reference follow these steps.

Dim m_Proj As CRAXDRT.Application 'Create a new COM instance of the Reports ' Run-time application
Dim WithEvents m_Report As CRAXDRT.report ' The dynamically generated report shell

'Make Connection object
Dim cn as new ADODB.Connection
Dim strConnProject as string
Dim sqlCurrentRiskListQuery as string

'Make Command Object
Dim datcmd1 As New ADODB.Command


Rate Add Graph,Groups,Total in Crystal Report at RunTime



Set m_Proj = New CRAXDRT.Application
Set m_Report = m_Proj.NewReport

'Make Query
sqlCurrentRiskListQuery = "SELECT RiskRevs.RiskLevel FROM Risks INNER JOIN RiskRevs ON Risks.RiskID = RiskRevs.RiskID Where RiskRevs.RiskLevel <> " & 0 & ""

'After Database Connection
 Set datcmd1 = New ADODB.Command
 Set datcmd1.ActiveConnection = cn
 datcmd1.CommandText = sqlCurrentRiskListQuery
 datcmd1.CommandType = adCmdText
 ' Add the datasource to the report
 m_Report.Database.AddADOCommand cn, datcmd1
 ' Add Section
 Dim crSection As CRAXDRT.Section

 Dim crFieldObject As CRAXDRT.FieldObject

'ADD Detailed Section 
Set crSection = m_Report.Sections.Item("D")
'Suppress Detailed Section
crSection.Suppress = True

Dim crDatabaseField As CRAXDRT.DatabaseFieldDefinition
'Make Field Objects
Dim crField As CRAXDRT.FieldObject
Dim crField2 As CRAXDRT.FieldObject

'Add table
   
Set crDatabaseField = m_Report.Database.Tables(1).Fields(1)

 'Add Group   
m_Report.AddGroup 0, crDatabaseField, crGCAnyValue, crAscendingOrder

'Add Group Header Section
Set crSection = m_Report.Sections.Item("GH")

'Add Table Field on Which we Want to Create Graph
Set crField = crSection.AddFieldObject("{ado.RiskLevel}", 2000, 0)

'Add Summary Field

Set crField = crSection.AddSummaryFieldObject("{ado.RiskLevel}", crSTCount, 3800, 0)

'Add Graph
    
Dim crGraphObject As CRAXDRT.GraphObject
Dim crSummaryField As CRAXDRT.SummaryFieldDefinition

'Since we are working with the Report Header section we need
'to get the 'RH' section of the report.
Set crSection = m_Report.Sections.Item("RH")

Set crGraphObject = crSection.AddGraphObject(crGroupGraph, 360, 0)

'Set crDatabaseField as the condition field for the graph
    crGraphObject.ConditionFields.Add ("{ado.RiskLevel}")

'Get the summary field for graph
Set crSummaryField = m_Report.SummaryFields(1)

'Set crSummaryField as the summary field for the graph
crGraphObject.SummaryFields.Add crSummaryField

    
'Set the Height, Width, Graph Color, Graph Direction,
'and Graph Type of the graph object
    With crGraphObject
        .Height = 5400
        .Width = 8400
        .GraphColor = crColorGraph
        .GraphDirection = crVerticalGraph
        .GraphType = crSideBySideBarGraph
    End With
    
Set crSection = m_Report.Sections.Item("RF")
Set crFieldObject = crSection.AddSummaryFieldObject("{ado.RiskLevel}", crSTCount, 3800, 100)
   
CrViewer1.ReportSource = m_Report
CrViewer1.ViewReport

Download this snippet    Add to My Saved Code

Add Graph,Groups,Total in Crystal Report at RunTime Comments

No comments have been posted about Add Graph,Groups,Total in Crystal Report at RunTime. Why not be the first to post a comment about Add Graph,Groups,Total in Crystal Report at RunTime.

Post your comment

Subject:
Message:
0/1000 characters