Solved

How to Change group Field at Runtime?

Posted on 2003-12-03
8
1,658 Views
Last Modified: 2012-05-04

I want to change group field for crystal report at runtime through vb code. In my Database , there are six classes.When user select  a one class from the combo box in the interface , it should be grouped only for that selected class.

I tried like following

In the general declaration

Dim crpApplication As New CRPEAuto.Application
Dim crpReport As CRPEAuto.Report

add reference as
Crystal Report Enegine 7 Object Libeary

in the form load event

Set crpReport = crpApplication.OpenReport(App.Path & "\Reports\TestReport1.rpt")

also created a formula field named "Group1" and its index is 5 in the crystal report.also created a group for cClass1 there.

in the button click event of showing report

CrystalReport1.ReportFileName = App.Path & "\Reports" & "\TestReport1.rpt"

crpReport.FormulaFields.Item(5).Text = "{ItemMaster.cClass2}"

CrystalReport1.Action = 1

but it always show records only taking the default gruop (cClass1).

How can I solve this problem?

I have crystal report 7 version and but can also install a higher version if necessary.

send me mail to Jayantha@iomworld.com

-Jayantha.
0
Comment
Question by:Retailigence
8 Comments
 
LVL 100

Expert Comment

by:mlmcc
ID: 9872519
The method is relatively easy

crpReport.GroupCondition(0) = "Group1;{View.FieldName};CONDITION;SORTORDER"

{View.FieldName} - the crystal name for the field or formula to group on

CONDITION - A reserved word indicating how the grouping occurs.
  for dates - DAILY, WEEKLY, BIWEEKLY, SEMIMONTHLY, MONTHLY, QUARTERLY, SEMIANNUALLY, ANNUALLY
  for boolean fields - TOYES, TONO, EVERYYES,EVERYNO, NEXTISYES, NEXTISNO
  all other fields - ANYCHANGE

0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 9872530
Sorry. Hit the wrong key.
SORTORDER - A ascending or D for descending

Example
crpReport.GroupCondition(0) = "Group1;{ItemMaster.cClass2};ANYCHANGE;A"

mlmcc
0
 
LVL 1

Expert Comment

by:MsLim
ID: 9872533
show cclass1 is not what you select , am I right ?
if yes , means you never use DiscardSave of this report and this must put before action.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 100

Expert Comment

by:mlmcc
ID: 9872537
I would recommnd you change and start using the RDC since the OCX has been dropped from CR9.

This should prove helpful in making the switch
http://support.crystaldecisions.com/communityCS/TechnicalPapers/scr8-ocxtordc.pdf.asp

mlmcc
0
 
LVL 22

Expert Comment

by:Ido Millet
ID: 9875712
Also, there are certain advantages to taking a slightly different approach.

In your report use a parameter to control a formula that returns different columns or expressions depending on the parameter value.  In your VB code, simply provide the parameter value.

Cheers,
- Ido
0
 
LVL 22

Expert Comment

by:_TAD_
ID: 9878037


All of the solutions provided are good, but the easiest method I have used requires three steps.

1) Create an input paramter of some type (I usually use a string)

2) Create a function that contains a reference to the parameter (you may also need to include "WhileReadingRecords;".

3) Create a group using the function you just created.


Now when you are in your VB code and you select something from your drop down list, you simply pass that Item as an input parameter and you are good to go!
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 9917456
Glad I could help
Generally I don't ask but why the C?

mlmcc
0
 
LVL 5

Expert Comment

by:vivekpv10
ID: 24720007
Here instemprpt indicates Crystal report object....
Dim newGroupField As CrystalDecisions.CrystalReports.Engine.FieldDefinition
        newGroupField = instemprpt.Database.Tables(0).Fields(2)
        instemprpt.DataDefinition.Groups(0).ConditionField = newGroupField

Open in new window

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question