Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change the crystal report layout at runtime from a vb app

Status
Not open for further replies.

chumki

Programmer
Jun 20, 2002
8
IN
I am creating a vb application for viewing crystal report.
I want to change the page layout of the report at runtime from the application,ie, the user of the application will have the liberty to change the report layout.
is it possible?
 
I don't know exactly what you want to do but it's possible using the Report Designer Component (RDC).

In VB6, go to Project, Reference and choose:
Crystal Report 8 ActiveX Designer Run Time Library

There are samples on the CrystalDecision web site.
You can create fields on the fly, groups, headers, change sorting, ... allmost all the things you can do in the design environment of Crystal Report, you can do it at runtime.

It looks like this:


(DECLARATION)
Public crxApplication As New CRAXDRT.Application

Public crxReport As CRAXDRT.Report

Public crxDatabase As CRAXDRT.Database
Public crxDatabaseTables As CRAXDRT.DatabaseTables
Public crxDatabaseTable As CRAXDRT.DatabaseTable

Public crxParamDefs As CRAXDRT.ParameterFieldDefinitions
Public crxParamDef As CRAXDRT.ParameterFieldDefinition

Public crxDatabaseField As CRAXDRT.DatabaseFieldDefinition
Public crxDatabaseField1 As CRAXDRT.DatabaseFieldDefinition
Public crxDatabaseField2 As CRAXDRT.DatabaseFieldDefinition
Public crxDatabaseField3 As CRAXDRT.DatabaseFieldDefinition

Public crxField As CRAXDRT.FieldObject
Public crxSection As CRAXDRT.Section
Public crxFieldObject As CRAXDRT.FieldObject


(SET THE DATABASES AND FIELDS)
Set crxReport = crxApplication.OpenReport("C:\blabla.rpt")
Set crxDatabase = crxReport.Database
Set crxDatabaseTables = crxDatabase.Tables
Set crxDatabaseTable = crxDatabaseTables.Item(1)
Call crxDatabaseTable.SetPrivateData(3, cdoSet)

Set crxDatabaseField1 = crxDatabaseTables.Item(1).Fields.Item(4)
Set crxDatabaseField2 = crxDatabaseTables.Item(1).Fields.Item(2)
Set crxDatabaseField3 = crxDatabaseTables.Item(1).Fields.Item(3)


crxReport.DiscardSavedData


(SET PARAMETERS)
Set crxParamDefs = crxReport.ParameterFields

For Each crxParamDef In crxParamDefs
With crxParamDef
Select Case .ParameterFieldName
Case "Employee"
.AddCurrentRange xStartEmpl, xEndEmpl, crRangeIncludeLowerBound
End Select
End With
Next


(ADD GROUP, FIELD,
crxReport.AddGroup 0, crxDatabaseField1, crGCAnyValue, crAscendingOrder
Set crxSection = crxReport.Sections.Item("GH")
Set crxField = crxSection.AddFieldObject("{@Resource}", 100, 0)

Set crxSection = crxReport.Sections.Item("GF")
Set crxDatabaseField = crxDatabaseTables.Item(1).Fields.Item(9)
Set crxFieldObject = crxSection.AddSummaryFieldObject(crxDatabaseField, crSTSum, 9040, 100)
Set crxDatabaseField = crxDatabaseTables.Item(1).Fields.Item(10)
Set crxFieldObject = crxSection.AddSummaryFieldObject(crxDatabaseField, crSTSum, 10315, 100)

(SORT YOUR DATA)
crxReport.RecordSortFields.Add crxDatabaseField1, crAscendingOrder
crxReport.RecordSortFields.Add crxDatabaseField3, crDescendingOrder


(PUT THE CRYSTAL VIEWER CONTROL ON YOUR FORM)

CRViewer1.ReportSource = crxReport
CRViewer1.EnableGroupTree = False
CRViewer1.EnableAnimationCtrl = True
CRViewer1.Zoom (100)
CRViewer1.ViewReport


There's a lot more of possibilities. You can code that you want your data to be export, or automatically print, ...

Pascal Theroux
Sorel Forge Inc.
 
Hi,
I want to change the print layout of the report from VB application at runtime
 
Sir,

I am using VB6 with Crystal Report 7.0. I created a query in the access database file. Based on the query i generated a instant report by using crystal report selecting the option 'SQL' as data source. In future i have to pass the parameter to query and existing crystal report design has to use. Please guide in this regard.

Thanks

N.S. Ravichandran
ravi@pondy.pon.nic.in
 
NS Since this reply is unrelated to the thread, please start a new thread. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Hi,
I understand the RDC gives you a great deal of runtime flexibility (including formatting). But our VB app uses .OCX with CR 8.5 Is it possible to enable the user to change the format using OCX?

Thanks.
JS
 
Depends on the type of changes you want to make. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top