Conditionally Replicating Group Header
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Conditionally Replicating Group Header

  1. #1
    Join Date
    Nov 2008
    Location
    Calgary, Alberta, Canada
    Posts
    3

    Question Conditionally Replicating Group Header

    Hi,

    I am new to Crystal Reports, but I have been coding with VBA in ArcGIS for a few years now.

    I am populating parameters in a group header in an existing Crystal Report with variables from within my code (the variables are taken from features in a ArcMap project, but that is not important). I can pass the parameters in with no problem. My problem is that the existing crystal report has one instance of the group header that I am populating parameters in. Depending on the number of variables created in the code, I need to 'replicate' the group header (and all of the parameters inside it) one or more times and then populate these parameters.

    So the final product that I am hoping for is a report with a conditonal number of group headers that are identical except for the values of the parameters inside them.

    Is there a way to copy the empty group header (and the parameters inside it) and paste it directly below its initial instance?

    Thanks in advance,
    Scott

    Here is a sample of my code. I removed irrelevant parts and put in some rough pseudoCode explaining what I hope to do.

    Code:
        Dim Num_Crossings as Long
        
        Dim CrApp As CRAXDRT.Application
        Set CrApp = New CRAXDRT.Application
    
        'Initialize crystal report
        Dim crReport As CRAXDRT.Report
        Set crReport = CrApp.OpenReport(".\Pipeline Crossing Summary.rpt", 1)
        crReport.DiscardSavedData
        
        'Determine the number of pipeline crossings
        'This is done using ArcGIS tools and the code is not relevant to my question
    	
        'Create arrays for passing into parameters
        Dim Comp_Name(Num_Crossings) as String
        Dim Area_Office(Num_Crossings) as String
    	
        'Populate the arrays
        'This is done using ArcGIS tools and the code is not relevant to my question
        
        Dim crGroup as Crystal Report Group          '<-pseudo code
        Set crGroup = crReport.Group(index)          '<-pseudo code
    
        crGroup.copy() 						'<-pseudo code
    
        For i = 0 to Num_Crossings 			'<-pseudo code
        	crGroup.Paste() 				        '<-pseudo code
        	crReport.ParameterFields.GetItemByName("Company").SetCurrentValue _
                 Comp_Name(i)  '<-probably need a new parameter each time
        	crReport.ParameterFields.GetItemByName("Office").SetCurrentValue _
                 Area_Office(i)    '<-probably need a new parameter each time
        Next i
    Last edited by scott.fraser; November 22nd, 2008 at 02:10 PM.

  2. #2
    Join Date
    Aug 2007
    Posts
    143

    Re: Conditionally Replicating Group Header

    I'm not real sure I understand what you are trying to do, but to your question
    "Is there a way to copy the empty group header (and the parameters inside it) and paste it directly below its initial instance?"

    In crystal, if you access the section expert (under the report menu or point in the gray area to the left of the design tab and right click) you can insert additional group headers and footers. These additional sections can be suppressed conditionally through a formula (also available on the section expert)

  3. #3
    Join Date
    Nov 2008
    Location
    Calgary, Alberta, Canada
    Posts
    3

    Re: Conditionally Replicating Group Header

    Thanks for your speedy reply.

    I'll try and explain a little better. I have an existing report and in that report I have a group for reporting on a pipeline crossing (Pipeline Company, Area Office, Location, etc.). However, this report needs to be capable of handling an unknown number of pipeline crossings. This means that the group needs to be 'copied' for as many pipeline crossings as the program encounters. Each of these groups will be have parameters (Company Name, etc.) that are populated by variables in my VB code.

    Your suggestion could be a work around. However, at runtime I don't know how many groups I am going to need. It depends on the number of pipeline crossings that occur. The number could be anything from 1 to 20 or more. I would like to add the groups programmatically only when they are needed. And I would like them to all be formatted the same as the one already in the existing report.

    With your method I could create say 50 group headers and suppress the ones that are not needed, but that seems a little inefficient. It still might work, though.

    All I really need is the syntax for creating a group object or group header object in VB and creating this new group in the report. Once I have that I should be able to set a group object to the existing group and then create identical new groups by copying that group object.

    pseudoCode:
    Code:
    Dim crReport As CRAXDRT.Report
    Dim ExistingGroup As CRAXDRT.Group '<-not the correct variable type
    Set ExistingGroup = crReport.Group(1) '<-not the correct way of accessing a group
    
    Dim CopyGroup As CRAXDRT.Group '<-not the correct variable type
    Set CopyGroup = ExistingGroup
    
    crReport.AddGroup CopyGroup '<-not the correct way of adding group to report
    Last edited by scott.fraser; November 24th, 2008 at 10:31 AM.

  4. #4
    Join Date
    Aug 2007
    Posts
    143

    Re: Conditionally Replicating Group Header

    I don't believe you can create group headers at run time. I'm afraid you will have to insert multiple copies of your group headers at design tim and suppress as needed at runtime. You can copy all objects at once from a group header and past into you new headers. The only limit is that graphic objects must be copies separately from all database and/or text objects.

    Good luck

  5. #5
    Join Date
    Nov 2008
    Location
    Calgary, Alberta, Canada
    Posts
    3

    Red face Re: Conditionally Replicating Group Header

    I suspected that this might be the case.

    Thanks for your help

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center