Solved

change group field from VB

Posted on 2004-08-10
5
200 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
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…

777 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