Friday, October 15, 2010

Suppress Subreport

How to suppress a subreport of main report in Crystal Report.

Suppress a subreport if there are no record found.

I am not sure but you can't really suppress a subreport in runtime.


But you can follows following details and get required result.


My DataTable has an extra column that will tell me whether or not I have to suppress the subreport. Then while in CR designer, right click on the subreport you want to supress and select FORMAT. Check the suppress checkbox and then click on the formula button (X2). Within your script check for the column value:


if {YourDataTable.YourColumn} = "Value" then
true
else
false

Another way you can suppress your detail section of Crystal Report from code behind page of form where you display your report.

Private Sub Report_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
       
            Me.WindowState = FormWindowState.Maximized

      
                Dim crt As New CrystalReport1

                // ds is DataSet which is not empty means it has record


                crt.SetDataSource(ds)
                If (ds.Table(2).Rows.Count <= 0) Then

                    crt.ReportDefinition.Sections("DetailSection3").SectionFormat.EnableSuppress = True
                 
                End If      
                CrystalReportViewer1.ReportSource = crt
                CrystalReportViewer1.Show()        
   Catch ex As Exception
            Throw ex
        End Try
      
    End Sub
End Class


Hopefully these information will help you.

Thanks and regard
Sumedh Borkar