Suppressing Crystal report detail section at runtime

  • Thread starter Thread starter Bill Nguyen
  • Start date Start date
B

Bill Nguyen

I have the need to suppress a Crystal report detail section at runtime (when
user selects "Summary" instead of "Detail"). The report created in CR 8.5
and loaded using .ReportDocument . I couldn't find anything in
ReportDocument control regarding this function.
Any suggestion is greatly appreciated.
Bill
 
Bill Nguyen said:
I have the need to suppress a Crystal report detail section at
runtime (when user selects "Summary" instead of "Detail"). The report
created in CR 8.5 and loaded using .ReportDocument . I couldn't find
anything in ReportDocument control regarding this function.
Any suggestion is greatly appreciated.
Bill

A CrystalDecisions.CrystalReports.Engine.ReportDocument object has a
ReportDefinition property. It returns a
CrystalDecisions.CrystalReports.Engine.ReportDocument.ReportDefinition
object. The object has a Sections property. You can use a loop to process
the sections. A section has a Kind property. The section that's "Kind"
property is AreaSectionKind.Detail is the detail section.

Or: When you create an instance of your derived ReportDocument, each section
is added as a property. If you rename the detail section to "detail", you
can access the section: MyDocument.Detail.

The Sectionformat property of a Section object has a EnableSuppress
property. You can set it to True to suppress the section.
 
Armin;
Thanks for the tip.
I used ReportDocument and it worked. However, there are some problems
associated with this:

You have to treat each report differently depending on the number of
sections you have in it. There is no universal section name/label that you
can use. For example, I have 1 report with 7 sections, another with 9 (I use
sections.count to display the sections). The section count includes
suppressed and non-suppressed sections. The .Sections(x), however, only
counts non-suppressed sections. I don't know of any way to get section
name/label so that I can just use the following code:

reportDocument1.ReportDefinition.Sections("SECTION_NAME").SectionFormat.Enab
leSuppress = True



If this is possible, I can just label the section following a naming
convention for all of my reports and the code will work for all of them.

Thanks

Bill
 
Bill Nguyen said:
Armin;
Thanks for the tip.
I used ReportDocument and it worked. However, there are some problems
associated with this:

You have to treat each report differently depending on the number of
sections you have in it. There is no universal section name/label that you
can use. For example, I have 1 report with 7 sections, another with 9 (I use
sections.count to display the sections). The section count includes
suppressed and non-suppressed sections. The .Sections(x), however, only
counts non-suppressed sections.

I can't repro this. The Sections property contains all sections, no matter
if suppressed or not. I used the following code:

Dim rpt As New CrystalReport2
Dim sec As CrystalDecisions.CrystalReports.Engine.Section

Debug.WriteLine("Before suppressing detail section:")
Debug.WriteLine(rpt.ReportDefinition.Sections.Count())

For Each sec In rpt.ReportDefinition.Sections
Debug.WriteLine(sec.Name)
Next

rpt.detail.SectionFormat.EnableSuppress = True

Debug.WriteLine("After suppressing detail section:")
Debug.WriteLine(rpt.ReportDefinition.Sections.Count())

For Each sec In rpt.ReportDefinition.Sections
Debug.WriteLine(sec.Name)
Next


Output:

Before suppressing detail section:
5
Section1
Section2
detail
Section4
Section5
After suppressing detail section:
5
Section1
Section2
detail
Section4
Section5

I don't know of any way to get section
name/label so that I can just use the following code:

reportDocument1.ReportDefinition.Sections("SECTION_NAME").SectionFormat.Enab
leSuppress = True

This works for me:
rpt.ReportDefinition.Sections("detail").SectionFormat.EnableSuppress = True

If this is possible, I can just label the section following a naming
convention for all of my reports and the code will work for all of them.

I'm not a fan of "late binding". Means, if one of your report (mistakenly)
has a different name, or you wrote the wrong section name in your code, the
compiler can't find this error, whereas using the typed reference using
"report.detail." can be checked at compile time. But that's up to you, I can
only say that the code above worked for me.
 
hi !

the simplest way is to create a boolean parameter and use this param inside the 'supress' property
of your detail section (using a formula)
 
Benoit;
I created a parameter "p_suppress" in the report and used the following
codes (from Brian's CR book online webpage). Got error
"CrystalDecisions.Shared - Invalid Object type"
What did I do wrong?
Thanks
Bill
--------------------

dim rptSum as boolean
*** actually, rptSUM is passed from the calling sub.

reportDocument1.Load(crRptName)

Dim ParameterFields As CrystalDecisions.Shared.ParameterFields

Dim ParameterField As CrystalDecisions.Shared.ParameterField

ParameterFields = New CrystalDecisions.Shared.ParameterFields

ParameterField = New CrystalDecisions.Shared.ParameterField

ParameterField.ParameterFieldName = "p_suppress"

ParameterField.CurrentValues.Add(rptSum)

ParameterFields.Add(ParameterField)

With myCrystal.CrystalReportViewer1

..ReportSource() = reportDocument1

..SelectionFormula = mSelection

..ParameterFieldInfo = ParameterFields

..RefreshReport()

End With
 
Found problem! I forgot to add the discretevalue .
now I have a new problem, The report still prompts for the value of
p_suppress (True or False). In VB6, you can suppress it. I just don't know
how to do it in VB.NET.
Please help.
Thanks
Bill
 
You can use the 'SetParameterValue' method of the ReportDocument object to pass param infos more
easily ...
 
I want to suppress whole detail section if my group is suppressed. I suppressed group on this condition: if purchase date > the date entered in parameter field.
 
Back
Top