Solved

How to Change group Field at Runtime?

Posted on 2003-12-03
8
1,657 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now