Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Cyrstal Reports subreport Section hiding

Cyrstal Reports subreport Section hiding

Scheduled Pinned Locked Moved Visual Basic
learning
12 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jinxster
    wrote on last edited by
    #1

    Dear all, I have a crystal report which has a lot of detaildections. In 3 sections there are 3 subreports. (1 subreport per section). If there is no data available I would like to hide the section. This works perfectly for the no subreport sections. It also works perfectly if there is no data in the whole subreport. However in some cases the subreport also has section and if there is not data for that one particular section I would like to hide it. I can do this, but then it hides that section for all records in that subreport. I only want it for that specific section. I hope that makes sense. If you need more info please ask. My code is as follows:

    Do While Not rs.EOF
    bFound = True
    With dsCVForClient
    .dtPersonalDetails.Rows.Add(rs.Fields(0).Value, rs.Fields(1).Value, rs.Fields(2).Value, rs.Fields(3).Value, rs.Fields(4).Value, rs.Fields(5).Value, rs.Fields(6).Value, rs.Fields(7).Value, rs.Fields(8).Value, rs.Fields(9).Value, rs.Fields(10).Value, rs.Fields(11).Value, rs.Fields(12).Value, rs.Fields(13).Value, rs.Fields(14).Value, rs.Fields(15).Value, rs.Fields(16).Value, rs.Fields(17).Value, rs.Fields(18).Value, rs.Fields(19).Value, rs.Fields(20).Value, rs.Fields(21).Value, rs.Fields(22).Value, rs.Fields(23).Value, rs.Fields(24).Value, sClient, sVacancy, sConsultant)
    rsInHouse = gCnn.Execute("select regno, tertiaryinstitute, course, duration, completed, subjects from tertiaryeducation where regno = '" & sRegNo & "'")
    Do While Not rsInHouse.EOF
    For i = 0 To 5
    If rsInHouse.Fields(i).Value = "" Then sTertiaryEducation(i) = "Not specified" Else sTertiaryEducation(i) = rsInHouse.Fields(i).Value
    Next
    .dtInHouseOtherCourses.Rows.Add(sTertiaryEducation(0), sTertiaryEducation(1), sTertiaryEducation(2), sTertiaryEducation(3), sTertiaryEducation(4), sTertiaryEducation(5))
    rsInHouse.MoveNext()
    Loop
    rsJobHistory = gCnn.Execute("select regno, company, jobtitle, datestarted, dateleft, tasks, reasonleft, duties from jobhistory where regno = '" & sRegNo & "' order by datestarted DESC")
    Do While Not rsJobHistory.EOF
    For i = 0 To 6
    If rsJobHistory.Fields(i).Value = "" Then sJobHistory(i) = "Not specified" Else sJobHistory(i) = rsJobHistory.Fields(i).Value
    Next
    If rsJobHist

    D 2 Replies Last reply
    0
    • J jinxster

      Dear all, I have a crystal report which has a lot of detaildections. In 3 sections there are 3 subreports. (1 subreport per section). If there is no data available I would like to hide the section. This works perfectly for the no subreport sections. It also works perfectly if there is no data in the whole subreport. However in some cases the subreport also has section and if there is not data for that one particular section I would like to hide it. I can do this, but then it hides that section for all records in that subreport. I only want it for that specific section. I hope that makes sense. If you need more info please ask. My code is as follows:

      Do While Not rs.EOF
      bFound = True
      With dsCVForClient
      .dtPersonalDetails.Rows.Add(rs.Fields(0).Value, rs.Fields(1).Value, rs.Fields(2).Value, rs.Fields(3).Value, rs.Fields(4).Value, rs.Fields(5).Value, rs.Fields(6).Value, rs.Fields(7).Value, rs.Fields(8).Value, rs.Fields(9).Value, rs.Fields(10).Value, rs.Fields(11).Value, rs.Fields(12).Value, rs.Fields(13).Value, rs.Fields(14).Value, rs.Fields(15).Value, rs.Fields(16).Value, rs.Fields(17).Value, rs.Fields(18).Value, rs.Fields(19).Value, rs.Fields(20).Value, rs.Fields(21).Value, rs.Fields(22).Value, rs.Fields(23).Value, rs.Fields(24).Value, sClient, sVacancy, sConsultant)
      rsInHouse = gCnn.Execute("select regno, tertiaryinstitute, course, duration, completed, subjects from tertiaryeducation where regno = '" & sRegNo & "'")
      Do While Not rsInHouse.EOF
      For i = 0 To 5
      If rsInHouse.Fields(i).Value = "" Then sTertiaryEducation(i) = "Not specified" Else sTertiaryEducation(i) = rsInHouse.Fields(i).Value
      Next
      .dtInHouseOtherCourses.Rows.Add(sTertiaryEducation(0), sTertiaryEducation(1), sTertiaryEducation(2), sTertiaryEducation(3), sTertiaryEducation(4), sTertiaryEducation(5))
      rsInHouse.MoveNext()
      Loop
      rsJobHistory = gCnn.Execute("select regno, company, jobtitle, datestarted, dateleft, tasks, reasonleft, duties from jobhistory where regno = '" & sRegNo & "' order by datestarted DESC")
      Do While Not rsJobHistory.EOF
      For i = 0 To 6
      If rsJobHistory.Fields(i).Value = "" Then sJobHistory(i) = "Not specified" Else sJobHistory(i) = rsJobHistory.Fields(i).Value
      Next
      If rsJobHist

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      What logic are you using to hide/unhide the section ? I just don't see it. :confused: You have to remember that when you create a "Supression" formula in Crystal, you have to make sure that you have logic to both hide (supress=true) and unhide (supress=false). Regards, David

      J 1 Reply Last reply
      0
      • D David Mujica

        What logic are you using to hide/unhide the section ? I just don't see it. :confused: You have to remember that when you create a "Supression" formula in Crystal, you have to make sure that you have logic to both hide (supress=true) and unhide (supress=false). Regards, David

        J Offline
        J Offline
        jinxster
        wrote on last edited by
        #3

        Hi David, Thank you for your reply. Ok the reason you dont see it is becuase maybe my brain is on overload and I posted the section it populates the dataset. The reason being is I thought maybe it could be done there somewhere. But on second thought it cant be done there. A short sample:

        If dsCVForClient.dtPersonalDetails(0).ComputerPackages = "" Then rpt.DetailSection49.SectionFormat.EnableSuppress = True

        If dsCVForClient.dtInHouseOtherCourses.Count = 0 Then rpt.DetailSection50.SectionFormat.EnableSuppress = True

        To get to the subreport, i used: rpt.Subreports(0).ReportDefinition.Sections(5).SectionFormat.EnableSuppress = True But it led to the seciont being suppressed for all the records in the subreport. The personaldetails will only ever have 1 record for this report, but the subreports could have anything from 0 to 100 records.

        D 1 Reply Last reply
        0
        • J jinxster

          Hi David, Thank you for your reply. Ok the reason you dont see it is becuase maybe my brain is on overload and I posted the section it populates the dataset. The reason being is I thought maybe it could be done there somewhere. But on second thought it cant be done there. A short sample:

          If dsCVForClient.dtPersonalDetails(0).ComputerPackages = "" Then rpt.DetailSection49.SectionFormat.EnableSuppress = True

          If dsCVForClient.dtInHouseOtherCourses.Count = 0 Then rpt.DetailSection50.SectionFormat.EnableSuppress = True

          To get to the subreport, i used: rpt.Subreports(0).ReportDefinition.Sections(5).SectionFormat.EnableSuppress = True But it led to the seciont being suppressed for all the records in the subreport. The personaldetails will only ever have 1 record for this report, but the subreports could have anything from 0 to 100 records.

          D Offline
          D Offline
          David Mujica
          wrote on last edited by
          #4

          If appears that your logic sets the suppression to "TRUE", but never sets it to "FALSE". I think the answer is to put an Else clause and set the suppression to FALSE. give it a try. :cool:

          J 1 Reply Last reply
          0
          • D David Mujica

            If appears that your logic sets the suppression to "TRUE", but never sets it to "FALSE". I think the answer is to put an Else clause and set the suppression to FALSE. give it a try. :cool:

            J Offline
            J Offline
            jinxster
            wrote on last edited by
            #5

            Thank you, that was a great suggestion. The bad news is though, it didnt work. What happens then is it enabled the section for all the records again. So if the last record did have a vaule in the field it unhid the section for all the records.

                For i = 0 To dsCVForClient.dtInHouseOtherCourses.Count - 1
                    If dsCVForClient.dtInHouseOtherCourses(i).Subjects = "" Then rpt.Subreports(0).ReportDefinition.Sections(5).SectionFormat.EnableSuppress = True Else rpt.Subreports(0).ReportDefinition.Sections(5).SectionFormat.EnableSuppress = False
                Next
            

            I seem to think the secret lies in the rpt.Subreports(0).ReportDefinition is there some way to talk to a record in that subreport? :confused:

            D 1 Reply Last reply
            0
            • J jinxster

              Thank you, that was a great suggestion. The bad news is though, it didnt work. What happens then is it enabled the section for all the records again. So if the last record did have a vaule in the field it unhid the section for all the records.

                  For i = 0 To dsCVForClient.dtInHouseOtherCourses.Count - 1
                      If dsCVForClient.dtInHouseOtherCourses(i).Subjects = "" Then rpt.Subreports(0).ReportDefinition.Sections(5).SectionFormat.EnableSuppress = True Else rpt.Subreports(0).ReportDefinition.Sections(5).SectionFormat.EnableSuppress = False
                  Next
              

              I seem to think the secret lies in the rpt.Subreports(0).ReportDefinition is there some way to talk to a record in that subreport? :confused:

              D Offline
              D Offline
              David Mujica
              wrote on last edited by
              #6

              You can write a fomula to supress the "detail" section of the subreport, effectively suppressing the output for each record as you see fit.

              J 1 Reply Last reply
              0
              • D David Mujica

                You can write a fomula to supress the "detail" section of the subreport, effectively suppressing the output for each record as you see fit.

                J Offline
                J Offline
                jinxster
                wrote on last edited by
                #7

                Thats what I am looking for. The question is how do i get to each record? You havent got some code? (just the object with the periods...) :-D

                1 Reply Last reply
                0
                • J jinxster

                  Dear all, I have a crystal report which has a lot of detaildections. In 3 sections there are 3 subreports. (1 subreport per section). If there is no data available I would like to hide the section. This works perfectly for the no subreport sections. It also works perfectly if there is no data in the whole subreport. However in some cases the subreport also has section and if there is not data for that one particular section I would like to hide it. I can do this, but then it hides that section for all records in that subreport. I only want it for that specific section. I hope that makes sense. If you need more info please ask. My code is as follows:

                  Do While Not rs.EOF
                  bFound = True
                  With dsCVForClient
                  .dtPersonalDetails.Rows.Add(rs.Fields(0).Value, rs.Fields(1).Value, rs.Fields(2).Value, rs.Fields(3).Value, rs.Fields(4).Value, rs.Fields(5).Value, rs.Fields(6).Value, rs.Fields(7).Value, rs.Fields(8).Value, rs.Fields(9).Value, rs.Fields(10).Value, rs.Fields(11).Value, rs.Fields(12).Value, rs.Fields(13).Value, rs.Fields(14).Value, rs.Fields(15).Value, rs.Fields(16).Value, rs.Fields(17).Value, rs.Fields(18).Value, rs.Fields(19).Value, rs.Fields(20).Value, rs.Fields(21).Value, rs.Fields(22).Value, rs.Fields(23).Value, rs.Fields(24).Value, sClient, sVacancy, sConsultant)
                  rsInHouse = gCnn.Execute("select regno, tertiaryinstitute, course, duration, completed, subjects from tertiaryeducation where regno = '" & sRegNo & "'")
                  Do While Not rsInHouse.EOF
                  For i = 0 To 5
                  If rsInHouse.Fields(i).Value = "" Then sTertiaryEducation(i) = "Not specified" Else sTertiaryEducation(i) = rsInHouse.Fields(i).Value
                  Next
                  .dtInHouseOtherCourses.Rows.Add(sTertiaryEducation(0), sTertiaryEducation(1), sTertiaryEducation(2), sTertiaryEducation(3), sTertiaryEducation(4), sTertiaryEducation(5))
                  rsInHouse.MoveNext()
                  Loop
                  rsJobHistory = gCnn.Execute("select regno, company, jobtitle, datestarted, dateleft, tasks, reasonleft, duties from jobhistory where regno = '" & sRegNo & "' order by datestarted DESC")
                  Do While Not rsJobHistory.EOF
                  For i = 0 To 6
                  If rsJobHistory.Fields(i).Value = "" Then sJobHistory(i) = "Not specified" Else sJobHistory(i) = rsJobHistory.Fields(i).Value
                  Next
                  If rsJobHist

                  D Offline
                  D Offline
                  David Mujica
                  wrote on last edited by
                  #8

                  Here is a basic idea of how I imagine you are using Crystal Reports. 1) Using Visual Studio (VS) you create a Crystal Report design (.rpt file) 2) Using VS you have your application display the report using the CrystalReportViewer. My example code is actually from an ASP.Net application, but the idea is the same.

                  Dim rpt As New ReportDocument

                  rpt.Load("\myReport1")

                  'For example purposes, imagine that the myDataSet is populated already

                  rpt.SetDataSource(myDataSet)

                  CrystalReportViewer1.ReportSource = rpt

                  Based on this design, you would put the hide/unhide logic in the Crystal ".RPT" file. You don't have to do anything programatically with VB. Is this how you are working with Crystal ? :~ From your examples, I don't think so. My impression is that the VB.net code should: 1) Create the dataset 2) Invoke the Crystal Report via the CrystalReportViewer and let Crystal do the formatting. Are we on the same page? :confused:

                  J 1 Reply Last reply
                  0
                  • D David Mujica

                    Here is a basic idea of how I imagine you are using Crystal Reports. 1) Using Visual Studio (VS) you create a Crystal Report design (.rpt file) 2) Using VS you have your application display the report using the CrystalReportViewer. My example code is actually from an ASP.Net application, but the idea is the same.

                    Dim rpt As New ReportDocument

                    rpt.Load("\myReport1")

                    'For example purposes, imagine that the myDataSet is populated already

                    rpt.SetDataSource(myDataSet)

                    CrystalReportViewer1.ReportSource = rpt

                    Based on this design, you would put the hide/unhide logic in the Crystal ".RPT" file. You don't have to do anything programatically with VB. Is this how you are working with Crystal ? :~ From your examples, I don't think so. My impression is that the VB.net code should: 1) Create the dataset 2) Invoke the Crystal Report via the CrystalReportViewer and let Crystal do the formatting. Are we on the same page? :confused:

                    J Offline
                    J Offline
                    jinxster
                    wrote on last edited by
                    #9

                    Hi David, We are on the same page. That is basically how mine works too...

                    Dim rpt As New rptCVForClient()

                    'Code to hide sections

                    Try
                    rpt.SetDataSource(dsCVForClient)
                    crvReport.ReportSource = rpt
                    Catch Excep As Exception
                    MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                    End Try

                    The problem is I have unbound text boxes in the sections that make the suppressing via property setting not work. I should probably change that, but I have never made a bound label in crystal reports... as er.. weird as that may sound.

                    D 1 Reply Last reply
                    0
                    • J jinxster

                      Hi David, We are on the same page. That is basically how mine works too...

                      Dim rpt As New rptCVForClient()

                      'Code to hide sections

                      Try
                      rpt.SetDataSource(dsCVForClient)
                      crvReport.ReportSource = rpt
                      Catch Excep As Exception
                      MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                      End Try

                      The problem is I have unbound text boxes in the sections that make the suppressing via property setting not work. I should probably change that, but I have never made a bound label in crystal reports... as er.. weird as that may sound.

                      D Offline
                      D Offline
                      David Mujica
                      wrote on last edited by
                      #10

                      Wow. I think you may have made your life harder by not using bound fields. I would start with working on getting all of your fields on the report to be bound to fields in the dataset. Or you can create formula fields that are based on fields in the dataset. The report shouldn't be that complicated.

                      J 1 Reply Last reply
                      0
                      • D David Mujica

                        Wow. I think you may have made your life harder by not using bound fields. I would start with working on getting all of your fields on the report to be bound to fields in the dataset. Or you can create formula fields that are based on fields in the dataset. The report shouldn't be that complicated.

                        J Offline
                        J Offline
                        jinxster
                        wrote on last edited by
                        #11

                        Hi David, thank you! The report is working as it should. Thanks for your perserverance and help! :thumbsup::thumbsup:

                        D 1 Reply Last reply
                        0
                        • J jinxster

                          Hi David, thank you! The report is working as it should. Thanks for your perserverance and help! :thumbsup::thumbsup:

                          D Offline
                          D Offline
                          David Mujica
                          wrote on last edited by
                          #12

                          Good to hear that everything is working now. I'm sure it is a big relief. On to the next challenge. :)

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups