Solved

How to Change group Field at Runtime?

Posted on 2003-12-03
8
1,659 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

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 …
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

730 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