Code:
Public Class frmMain
    Inherits System.Windows.Forms.Form
    Dim kofilename As String
    Dim streamToPrint, koread As StreamReader
    Dim kowrite As StreamWriter
    Dim myDocument As frmDocument
    Dim printfont As Font
Private Sub CreateNewDocument()
        Static count As Integer = 1
        myDocument = New frmDocument
        With myDocument
            .MdiParent = Me
            .Text = "Document" & count
            .Show()
            .Focus()
            count += 1
        End With
End Sub
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles ToolBar1.ButtonClick Select Case ToolBar1.Buttons.IndexOf(e.Button)
Case 5
                PrintPreviewDialog1.Document = PrintDocument1
                PrintPreviewDialog1.Show()

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim linesperpage As Single = 0
        Dim y As Single = 0
        Dim count As Integer = 0
        Dim left As Single = e.MarginBounds.Left
        Dim top As Single = e.MarginBounds.Top
        Dim line As String = Nothing

        streamToPrint = New StreamReader(myDocument.RichTextBox1.Text)
        linesperpage = e.MarginBounds.Height / printfont.GetHeight(e.Graphics)
        While count < linesperpage
            line = streamToPrint.ReadLine()
            If line Is Nothing Then
                Exit While
            End If
            y = top + count * printfont.GetHeight(e.Graphics)
            e.Graphics.DrawString(line, printfont, Brushes.Black, left, y, New StringFormat)
            count += 1
        End While
        If Not (line Is Nothing) Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
        End If
        'e.Graphics.DrawString(myDocument.Text, New Font("Times New Roman", 14, FontStyle.Bold), Brushes.Black, 150, 125)
    End Sub
Exception occur!!!How to change it so I can refer to myDocument???
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Windows.Forms.PrintPreviewControl.CalculatePageInfo()
at System.Windows.Forms.Control.InvokeMarshaledCallbacks()