Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to Change group Field at Runtime?

Posted on 2003-12-03
8
Medium Priority
?
1,667 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 101

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 101

Accepted Solution

by:
mlmcc earned 1000 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
Hire Technology Freelancers with Gigs

Work with 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 101

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 23

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 101

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

610 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