Solved

change group field from VB

Posted on 2004-08-10
5
203 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:Jeremy Daley
[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
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 101

Expert Comment

by:mlmcc
ID: 11762342
0
 
LVL 4

Author Comment

by:Jeremy Daley
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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…
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 …
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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