New User needs help with new page events

Posted by: twilson7 on 4 August 2017, 2:50 pm EST

  • Posted 4 August 2017, 2:50 pm EST

    I am new to using the active reports designer in vb6 and need some assistance.



    This is what I have so far:



    In my report I have fields in the page header and in the detail section
    that are "dynamic".  There is an Adodb control in the detail
    section who's source is set to "Select * from table1 and table2", the
    password and connection string are currently hardcoded into the
    properties (although in the future this will have to become dynamic as
    well).



    Also, all my fields (in page header and detail) are set to items in a
    data collection that get set on the DataInitialize procedure call (i.e.
    Fields.add "Field1", Fields.add "Field2", etc.)



    Then based on user input from the program I build a query and store it
    in a module level string variable. I then call rs.open sqlString, Conn
    (my program's connection to the database)



    I set a Module-level variable (lets call it KEY) equal to one of the fields in the recordset (you'll see why in a second).



    the next step is the FetchData procedure.



    In fetchdata I set fields collection value  in the PageHeader and
    Detail section based on the current record.  I use KEY to make
    sure I don't need to start a new page because all the records
    pertaining to KEY should be on the same page. 



    If KEY <> rs!KeyField then

         key = rs!KeyField

        detail.newpage = ddnpBefore

    else

        detail.newpage = ddnpnone

    end if



    The problem:



    A new page does not get generated when Key <> rs!KeyField, it
    only happens if information in detail section is different from the
    previous record. 



    I have even added the value of the keyfield to the detail section to see what is happening, or just to try and force a new page.



    I have tried a few other things like forcing a new page after the page footer gets printed (nothing changed).



    I have a feeling I am setting up my database connection incorrectly, or
    that I am not using the correct even procedures to display what I want.



    What I am hoping for:

    Basically, when new page header information is in the current record, a
    new page should start and display in the details section all the other
    information in the record about that Key info.



    This could be likened to Customer information (name, address, etc) in
    the page header, and all the orders for this customer in the detail
    section, then a new page for a new customer.



    I am happy to offer more information if needed.  I have been
    looking through the help, and this forum but haven't come up with
    anything yet.  Thanks in advance.


  • Replied 4 August 2017, 2:50 pm EST

    As an update to this issue.  If I select three records to be
    printed, the first record contains no nulls, the second two records DO
    contain null values then



    record 1 prints fine (page header and detail section)

    record 2 prints the detail section correctly, but print record 3's Page Header info

    record 3 prints fine



    I now believe this problem is rooted with how the page header info is displayed/updated.



    What event triggers should I use to store the current record's
    information in the fields collection values for the fields contained in
    the page header that correspond with the details field values.






  • Replied 4 August 2017, 2:50 pm EST

    I would also add that some of the field values are returning a null
    value, and I have modified my fetchdata code to look like this

    activereport_fethcdata



    if rs.eof = true then

        EOF = true

        exit sub

    end if



    If key <> rs!keyfield then

        key = rs!keyfield

        detail.newpage = ddnpbefore

    elseif isnull(rs!DetailField1) then

        detail.newpage =ddnpafter

    else

        detail.newpage = ddnpNone

    end if



    fields("Field1").value = rs!Field1

    etc.

    rs.movenext



    end sub

    Which seems to be working, although I am not sure why.


  • Replied 4 August 2017, 2:50 pm EST

    In which event procedure would I call GroupFoot.NewPage, and what should it be set to?
  • Replied 4 August 2017, 2:50 pm EST

    I wouldn't recommend using the page break control in this case, instead use the NewPage property of the GroupFooter. It should function basically the same but without the training blank page.
  • Replied 4 August 2017, 2:50 pm EST

    Thanks for the help.  After a bit more toying I got everything
    figured out.  The last thing that I'm wondering about is that now
    an extra page is printing at the end of the report.  I think I saw
    something in the forums about this, but if you could refresh my memory
    I'd appreciate it.  Thanks again, I didn't even notice the page
    break control existed, that helps a lot.






  • Replied 4 August 2017, 2:50 pm EST

    What you can do:  If you make sure your sql statement orders by your key value, so that it is sorted.  You can create a group header/footer, set its data field to your key.  Set the Header Hieght to 0, put a page break in the group footer.  This should accomplish your goal.
  • Replied 4 August 2017, 2:50 pm EST

    Using a page break control or just setting the newpage property in the
    group footer didn't make a difference.  This is probably because
    the report does not know yet whether there is a new group (or record)
    coming next or if EOF = True.  Is there a way to "take back" the
    last page if it gets generated prior to the next fetchdata event (which
    would tell whether it was EOF or not).
  • Replied 4 August 2017, 2:50 pm EST

    http://www.datadynamics.com/forums/66973/ShowPost.aspx


    you can use the following code in your reportend event to always automatically remove the last page:


        Dim x As Long

        x = Me.Pages.Count
       
        ' decrement the page count to adjust for the variance in indicies

        x = x - 1

        Me.Pages.Remove x

  • Replied 4 August 2017, 2:50 pm EST

    Thanks for the suggestion.  I tried it but it didn't seem to make a difference.  I am ok with the extra page for now.



    Thanks to all who helped out.  Now onto my next post...lol.


  • Replied 4 August 2017, 2:50 pm EST

    Yes, you can do all kinds of page manipulation via the Pages collection of a report object.


    However you shouldn't be experiencing a page feed unless you actually have data to print, an EOF = TRUE should exit before another page is created, ddNPAfter to my understanding doesn't actually create a new page, it just marks that any more records that exist should be on another page. Though something like an empty ReportFooter could spawn the blank page too.


    As an alternative solution, try setting the NewPage property on your GroupHeader to ddNPBefore instead of any page breaking in your GroupFooter.

  • Replied 4 August 2017, 2:50 pm EST

    Since your GroupHeader's DataField should already be set to your KeyField the GroupFooter will only fire when the KeyField changes, so you shouldn't need to us any code. I would assume that since a page break control did that trick, other than the trailing blank page, that you would want to use ddNPAfter.
Need extra support?

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

Learn More

Forum Channels