Solved

How to Change group Field at Runtime?

Posted on 2003-12-03
8
1,654 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
 
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

11 Experts available now in Live!

Get 1:1 Help Now