variable in memory not refreshing

Posted by: kmac303 on 4 August 2017, 2:44 pm EST

  • Posted 4 August 2017, 2:44 pm EST

    Is there a way to use a global variable.... When I run the report and count the number of records inside the subreport it ends up not keeping the count for the next customer. So I put in a unnecessary newpage. RNumber keeps the number in memory even when the report ends.

    Private Sub Detail_Format()
    Static RNumber As Long
    RNumber = RNumber + 1

    If RNumber = 60 Then 'If there are 6 records in the column
                'it will add a new column and reset the counter
       Detail.NewPage = ddNPAfter

        RNumber = 0
    Else
        'Detail.NewColumn = ddNPNone 'This turns off the Add New column
        Detail.NewPage = ddNPNone
    End If

    End Sub

  • Replied 4 August 2017, 2:44 pm EST

    Are you reinitializing your subreport for each customer? Usually it is best to initialize your subreport once, parent's Reportstart event, then kill it in the parent's Reportend. In the parent's section's format for the sub, you feed it the new query constraint, recordset, array, etc.
  • Replied 4 August 2017, 2:44 pm EST

    Yeah, I am setting the subreport to:

    Private Sub ActiveReport_DataInitialize()
    Me.subRPTControl2.object.DataControl1.ConnectionString = "Provider=SQLOLEDB;Persist Security Info=False;User ID=temp;password=temp;Initial Catalog=tempDB;Data Source=devTest;"

    End Sub

    and counting how many interations within the Detail section are printing. Before that in the parent report I am :

    Private Sub ActiveReport_ReportStart()
        Set Me.subRPTControl2.object = New arQwestSub
        Set Me.subRPTControl4.object = New arQwestSub3
    End Sub


    Parent report again:
    Private Sub Detail_Format()
        Me.subRPTControl2.object.DataControl1.Source = "EXEC prcGetRefCodes1 " & Trim(Me.dcReport.Recordset!BillPhone)
        Me.subRPTControl4.object.DataControl3.Source = "EXEC prcGetRefCodes3 " & Trim(Me.dcReport.Recordset!BillPhone)
    End Sub

    Parent report again:
    Private Sub ActiveReport_ReportEnd()
      'Unloads the subreport object
        Unload Me.subRPTControl2.object
        Set Me.subRPTControl2.object = Nothing
        Unload Me.subRPTControl4.object
        Set Me.subRPTControl4.object = Nothing
    End Sub

    In the report end of the parent I unload both sub controls. How do I initialize the subreport in the parent/main report rather than the sub?

  • Replied 4 August 2017, 2:44 pm EST

    It doesn't seem to matter where I initialize the data. I moved it to the parent and it still keeps that variable( RNumber) inside the subreport in memory.


    Private Sub Detail_Format()
    'Static PNumber As Long
    Static RNumber As Long
    RNumber = RNumber + 1

    If RNumber = 60 Then 'If there are 6 records in the column
                'it will add a new column and reset the counter
        'Detail.NewColumn = ddNPAfter
        Detail.NewPage = ddNPAfter
        RNumber = 0
    '    PNumber = 0
    Else
        'Detail.NewColumn = ddNPNone 'This turns off the Add New column
        Detail.NewPage = ddNPNone
    End If

    End Sub

  • Replied 4 August 2017, 2:44 pm EST

    Nevermind I changed the Static to a Dim. I didn't notice it was a static until I truthfully looked at it. I took that code from the whitepapers...
  • Replied 4 August 2017, 2:44 pm EST

    It would of helped if I had read that you did NOT want it kept in memory...I was thinking the reverse.

    Yeah watch the copy and paste useage, always double check that you got what you really wanted. Smile
Need extra support?

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

Learn More

Forum Channels