BUG: Subreport misbehaviour in GroupFooter. (Example attached)

Posted by: ngchintamani on 4 August 2017, 3:06 pm EST

  • Posted 4 August 2017, 3:06 pm EST

    I am creating a Report in which I have to display the records like:



    Group Header Section--------------------------------

    Doc No:

    Doc Date:

    etc...

    Detail Section -----------------------------

    1. Item1 Qty Unit Rate Amount

    2. Item2 Qty Unit Rate Amount

    3. Item3 Qty Unit Rate Amount

    etc...

    Group Footer Section--------------------------------

    Tax 1 Rate Amount

    Tax 2 Rate Amount

    Tax 3 Rate Amount

    Tax 4 Rate Amount

    Total Amount

    -----------------------------------



    I put a subreport for the taxes in Group Footer Section linked by link DocID->DocID. But it misbehaves in footer or header section. While in Detail Section it prints correctly.

    Moreover I noticed that the value of the DocID in the subreport is of the next row of paren report.

    Means the cursor in the parent move to next position then subreport is processed (to the new DocID). so the subreport is shown at the previous row. Instead of that the subreport should be processed before the cursor of parent moves to next position.
    2007/09/MySample.rar
  • Replied 4 August 2017, 3:06 pm EST

    Try setting up the SubReport in the Format event of its parent Section. When you do this, you can use the text property of a TextBox control to build the SQL statement for the SubReport's report object. You can hide the TextBox if necessary. However, only reference a control in the same section to ensure you get the correct value.

    Tim
  • Replied 4 August 2017, 3:06 pm EST

    Hello,

    I am building the reports at runtime. So how can I use Format event of its parent Section?

    If I am not wrong we can do it by the Scripts or AddNamedItem... Can you please put some example of both methods?

    But one more thing I want to tell that i am building the reports from some tables in the DB. The whole process is totally automated and the reports are generated at runtime.
  • Replied 4 August 2017, 3:06 pm EST

    Hi,

    As you told, I used the Format event through scripts as:

    vbScript = "sub OnFormat" & vbCrLf

    vbScript = vbScript & "rpt.Sections(""GroupFooter1"").Controls(""subctrl"").object.DataControl1.Source = ""Select * from V_DocCharges where DocID=""" & vbCrLf

    vbScript = vbScript & "end sub"

    r.Detail.Script = vbScript



    This shows the same faulty report.



    But if I replace the 2nd line by either of the following lines then it works fine.

    'vbScript = vbScript & "rpt.Sections(""GroupFooter1"").Controls(""subctrl"").object.DataControl1.Source = ""Select * from V_DocCharges where DocID="" & rpt.Fields(""DocID"").Value " & vbCrLf



    OR



    ' vbScript = vbScript & "rpt.Detail.Controls(""Linksubctrl"").Text = rpt.Fields(""DocID"").Value" & vbCrLf

    ' vbScript = vbScript & "rpt.Sections(""GroupFooter1"").Controls(""subctrl"").object.DataControl1.Source = ""Select * from V_DocCharges where DocID="" & rpt.Detail.Controls(""Linksubctrl"").Text " & vbCrLf



    But one Question left in my mind is that logically above three lines are same but the result of first and other two is different.

    I have tried the same report in CR 10 and they are working fine.

    This certainly shows a BUG.
  • Replied 4 August 2017, 3:06 pm EST

    Hi,

    I also tried following lines in the Subreport (ActiveReport2 in the example) and there is also variance in the outputs.

    1. Faulty one.

    Private Sub ActiveReport_ReportStart()

    DataControl1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Persist Security Info=False"

    DataControl1.Source = "Select * from V_DocCharges where DocID=" & Me.ParentReport.object.Fields("DocID").Value

    End Sub





    2. Works Fine.

    Private Sub ActiveReport_ReportStart()

    DataControl1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Persist Security Info=False"

    End Sub



    Private Sub Detail_Format()

    DataControl1.Source = "Select * from V_DocCharges where DocID=" & Me.ParentReport.object.Fields("DocID").Value

    End Sub

  • Replied 4 August 2017, 3:06 pm EST

    You mentioned that your three options were logically the same. However, they were not. Currently, you are accessing the Fields collection in the detail format event. You should never access that outside of the FetchData or DataInitialize events. This is because the Fields collection will be updated whenever the reporting engine decides it needs new data. Even it it works fine now, it will not necessary always work.

    Instead, you should place a textbox in the same section as your subreport and read the value from it for your subreport's SQL statement. You may need to use a script to set the parameter value if you're building dynamic reports. I've attached a sample project that shows how to do this. You will need the Northwinds sample Access database.

    Tim
    2007/09/SRinGF.zip
  • Replied 4 August 2017, 3:06 pm EST

    I tried the following lines in the subreport.



    vbScript = "sub OnFormat" & vbCrLf

    vbScript = vbScript & "rpt.DataControl1.Source = ""Select * from V_DocCharges where DocID="" & rpt.ParentReport.object.Fields(""DocID"").Value " & vbCrLf

    vbScript = vbScript & "end sub"

    subctrl.object.Sections("Detail").Script = vbScript





    And it worked fine. I still have some doubts but I will work on it for more days.

    Thank a lot.
  • Replied 4 August 2017, 3:06 pm EST

    Just so you know, you should not access a report's datasource outside of the DataInitialize or ReportStart events. (You could access it in the procedure outside the report where you set it up, but you'll need to do that before you run the report.) However, if you use a Format event of the parent report to setup a SubReport control, that will work (because that happens before you run the subreport).

    Also do not access the Fields collection outside of the DataInitialize or FetchData events. Doing so can cause synchronization issues. This is because the reporting engine will fire the FetchData event and update its place in the Fields collection whenever it decides it needs a new row of data. However, if you access the Fields collection in another event, such as a section's Format event for example, it may be pointing to a different row than what the rest of the data in the section came from.

    Tim
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels