I need help on a printing problem in MS Reporting Services. It has to do with page advancement.
I have a code snippet below that I think should work. But, it doesn't. I think this should be a three page report with a person's name at the top of each page. But what I get in the print preview is one page with the second name overwriting the first and the third name overwriting the first and second. It's a one page report instead of a three page report.

My understanding is that the statement
e.hasMorePages = True
is the statement that should cause a page advance. So, I would think that it would print a name, page advance, print another name, page advance, etc.

To repeat, my goal is a three page report with a name at the top of each and what I have is a one page report with three names at the top of that one page.

Can anyone help me with why it's not page advancing after each name?

Following is the code that I have.

Public Class frmPeopleReportTest
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
    End Sub
    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles PrintDocument1.PrintPage
        Dim peopleNames As New List(Of String)({"Elizabeth", "David", "George"})
        Dim collectionPointer As Integer
        Dim personName As String
        For collectionPointer = 0 To 2
            personName = peopleNames(collectionPointer)
            Dim pFont As Font
            pFont = New Font("Verdana", 30)
            e.Graphics.DrawString(personName, pFont, Brushes.Black, 40, 15)
            e.HasMorePages = True
        Next
        e.HasMorePages = False
    End Sub
End Class

Hi KentuckyJoe,
Try this code.

Public Class frmPeopleReportTest
    Dim pagenumber As Integer = 1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        pagenumber = 1
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
    End Sub
    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) _
Handles PrintDocument1.PrintPage
        Dim peopleNames As New List(Of String)({"Elizabeth", "David", "George"})
        Dim personName As String
        If pagenumber <= peopleNames.Count Then
            personName = peopleNames(pagenumber - 1)
            Dim pFont As Font
            pFont = New Font("Verdana", 30)
            e.Graphics.DrawString(personName, pFont, Brushes.Black, 40, 15)
            e.HasMorePages = True
            pagenumber += 1
            Exit Sub
        End If
        e.HasMorePages = False
    End Sub
End Class

You have to exit the sub at the end of each page. The printdocument sub is recalled for each page. So the only thing that changes between pages is the data that is printed.
Curtis

This article has been dead for over six months. Start a new discussion instead.