Solved

change group field from VB

Posted on 2004-08-10
5
198 Views
Last Modified: 2012-05-05
how do i change the field that a group is grouped by in my report from Visual Basic?
0
Comment
Question by:daleyjem
5 Comments
 
LVL 10

Expert Comment

by:ebolek
ID: 11762254
This is hpw you do it in .net. VB must be similat to it.

Logic is
Create a formula field in the report.
Then in the vb find that formula field from formulafield collection
insert a group to the report by using the formula created
chnage the text propertty of the formula to the field that you want to group by in VB

Regards
Emre

private void ChangeGroupName(CrystalDecisions.CrystalReports.Engine.ReportDocument MyReport, string strGroupName)
            {
                  //change the group name for fieldday reports
                  
                  foreach(CrystalDecisions.CrystalReports.Engine.FormulaFieldDefinition crField in MyReport.DataDefinition.FormulaFields)
                  {
                        //start changing the header of the chart according to the group name passed
                        if (crField.Name  == "GroupField")
                        {
                              switch(strGroupName)
                              {
                                    case "client":
                                          crField.Text = "{uspReport_DaysWorked_View." + strGroupName + "}";
                                          break;
                                    case "rep_name":
                                          crField.Text = "{uspReport_DaysWorked_View." + strGroupName + "}";
                                          break;
                                    case "work_comp_state":
                                          crField.Text = "{uspReport_DaysWorked_View." + strGroupName + "}";
                                          break;
                                    default:
                                          crField.Text = "{uspReport_DaysWorked_View." + strGroupName + "}";
                                          break;
                              }                  
                        
                        }      
                        //start chart title formula field
                        if (crField.Name  == "ChartTitle")
                        {
                              switch(strGroupName)
                              {
                                    case "client":
                                          crField.Text = "\"Field Days Assigned By Client\"";
                                          break;
                                    case "rep_name":
                                          crField.Text = "\"Field Days Assigned By Sales Representative\"";
                                          break;
                                    case "work_comp_state":
                                          crField.Text = "\"Field Days Assigned By State\"";
                                          break;
                                    default:
                                          crField.Text = "\"Field Days Assigned By Ops Code\"";
                                          break;
                              }
                        
                        
                        }
                        
                        
                  }
                  
                  
                  
            
                 
            }
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 11762342
0
 
LVL 4

Author Comment

by:daleyjem
ID: 11765009
sorry mlmcc, but that link takes me to a forum where the link is a downloadable .exe

i figured out what i need to do...

before... i was using a crystal report control out of the VB6 toolbox.
this time, i actually referenced the Crystal Report 7 Engine Object, and also kept the crystal report control on my form with it's file name pointing to the right spot.

then i added this code:

    Dim crpApplication As New CRPEAuto.Application
    Dim crpReport As CRPEAuto.Report
    Dim crpDatabaseField As CRPEAuto.DatabaseFieldDefinition
    Set crpReport = crpApplication.OpenReport("c:\filename.rpt")

    If Option1.value = True Then
        Set crpDatabaseField = crpReport.Database.Tables.Item(1).Fields.Item(2)
    Else
        Set crpDatabaseField = crpReport.Database.Tables.Item(1).Fields.Item(1)
    End If

    'This is the group area of the report
    crpReport.Areas.Item(3).GroupOptions.ConditionField = crpDatabaseField
    'Display the report

    If Option1.value = True Then
        crpReport.FormulaFields(1).Text = "{Permissions.Procedure}"
    Else
        crpReport.FormulaFields(1).Text = "{Permissions.User}"
    End If

    crpReport.Preview

<--- End of Code --->

ebolek, i'm not real familiar with the syntax of your code...
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 11799600
Closed, 125 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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. …
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

867 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

21 Experts available now in Live!

Get 1:1 Help Now