Rerunning report with new data

Posted by: alfvaen on 4 August 2017, 3:10 pm EST

  • Posted 4 August 2017, 3:10 pm EST

    Currently we're using version 2.5.0.1308 of ActiveReports.  We have the following setup (somewhat simplified):

    strSql = GenerateSQL
    Set rsData = OpenRecordset(strSql)
    Set rpt.datADODB.Recordset = rsData
    rpt.Run
    Set frmARViewer.ARViewer1.ReportSource = rpt
    frmARViewer.Show 1

    This all works fine.  Now I want to be able to go back and change the SQL and rerun the exact same report (these are all generated on-the-fly at runtime) with different data.  So I tried adding the following:


    strSql = RecalculateSQL
    Set rsData = OpenRecordset(strSql)
    Set rpt.datADODB.Recordset = rsData
    rpt.Run
    frmARViewer.Show 1

    This doesn't work; the form comes up with the exact same data as before.

    I've tried using rpt.Restart before rpt.Run; I've tried using rpt.Pages.RemoveAll; I've tried setting the ARViewer's ReportSource property again.  Nothing seems to make the new report data come up.  Any other thoughts, or am I going to have to regenerate the report object from scratch?

    Aaron V. Humphrey
    Kakari Systems Ltd.

  • Replied 4 August 2017, 3:10 pm EST

    What my concern here is, you do not show how the ARViewer2 control is getting its ReportSource set.

    I've attached a sample where my ViewerForm has a property called Report where the main form passes its report to the ViewerForm.

    The following code worked as expected in my testing:
    Private rpt As New ActiveReport1

    Private Sub Command1_Click()
        Dim sql As String
       
        If DateTime.Second(DateTime.Now) < 30 Then
            sql = "SELECT TOP 10 * FROM Customers ORDER BY CustomerID ASC"
        Else
            sql = "SELECT TOP 10 * FROM Customers ORDER BY CustomerID DESC"
        End If
       
        Dim cn As New ADODB.Connection
        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\NWIND.MDB"
        cn.Open
       
        Dim cmd As New ADODB.Command
        cmd.ActiveConnection = cn
        cmd.CommandText = sql
       
       
        Dim rs As New ADODB.Recordset
        Set rs = cmd.Execute
       
        rpt.Restart
        Set rpt.DataControl1.Recordset = rs
       
        Dim viewer As New ViewerForm
        viewer.Report = rpt
        viewer.Show
    End Sub

    2008/05/Sample-2.zip
  • Replied 4 August 2017, 3:10 pm EST

    Never mind, it was just a PEBKAC error.  Apparently my new SQL was being erroneously generated the same as the old SQL, which was why the report never seemed to change.  Sorry for the noise.

Need extra support?

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

Learn More

Forum Channels