allora vi posto il mio codice:

codice:
Imports System.Windows.Forms
Imports ADODB
Imports Connection
Imports System.Drawing.Printing
Imports Microsoft.Office.Interop



Public Class Dialog2
    
    Shared rs As New ADODB.Recordset
    Shared objc As New Connection

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        PageSetupDialog1.Document = PrintDocument1
        If PageSetupDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
            'PrintDocument1.Print()
            If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                'PrintDocument1.Print()

                If PrintPreviewDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                    PrintDocument1.Print()
                End If
            End If
        End If
        Dim sql As String = "SELECT Cognome,nome,Indirizzo,Cap,Citta,Prov From arc_completo where tipo_iscritto='A' and Iscrizione_Avvocati is not NULL"
        objc.open_connection()
        rs = objc.esegui_query(sql, 1)
        
        'Percorso relativo Documents Application.StartupPath &

    End Sub
    

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

    Public Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim Font As New Font("Arial", 8)
        Static i As Integer = 0
        
        Dim X As Integer = 8

        


        Dim str As String
        Static Pagina As Integer
        Dim Parziale As Double
        Static Incrementale As Double
        Static Totale As Double
        Dim offset As Integer = 150
        Dim j As Integer = 0
        For i = i To i + 8
            If (rs.EOF = False) Then
                e.Graphics.DrawString("sign.", Font, Brushes.Black, X, 15 + (j * offset))
                e.Graphics.DrawString(rs("Cognome").Value, Font, Brushes.Black, X, 30 + (j * offset))
                e.Graphics.DrawString(rs("nome").Value, Font, Brushes.Black, X + 85, 30 + (j * offset))
                e.Graphics.DrawString(rs("Indirizzo").Value, Font, Brushes.Black, X, 45 + (j * offset))
                e.Graphics.DrawString(rs("Cap").Value, Font, Brushes.Black, X, 60 + (j * offset))
                e.Graphics.DrawString(rs("Citta").Value, Font, Brushes.Black, X + 40, 60 + (j * offset))
                e.Graphics.DrawString(rs("Prov").Value, Font, Brushes.Black, X + 200, 60 + (j * offset))
                rs.MoveNext()

                e.Graphics.DrawString("sign.", Font, Brushes.Black, X + 300, 15 + (j * offset))
                e.Graphics.DrawString(rs("Cognome").Value, Font, Brushes.Black, X + 300, 30 + (j * offset))
                e.Graphics.DrawString(rs("nome").Value, Font, Brushes.Black, X + 385, 30 + (j * offset))
                e.Graphics.DrawString(rs("Indirizzo").Value, Font, Brushes.Black, X + 300, 45 + (j * offset))
                e.Graphics.DrawString(rs("Cap").Value, Font, Brushes.Black, X + 300, 60 + (j * offset))
                e.Graphics.DrawString(rs("Citta").Value, Font, Brushes.Black, X + 340, 60 + (j * offset))
                e.Graphics.DrawString(rs("Prov").Value, Font, Brushes.Black, X + 510, 60 + (j * offset))
                rs.MoveNext()

                e.Graphics.DrawString("sign.", Font, Brushes.Black, X + 600, 15 + (j * offset))
                e.Graphics.DrawString(rs("Cognome").Value, Font, Brushes.Black, X + 600, 30 + (j * offset))
                e.Graphics.DrawString(rs("nome").Value, Font, Brushes.Black, X + 685, 30 + (j * offset))
                e.Graphics.DrawString(rs("Indirizzo").Value, Font, Brushes.Black, X + 600, 45 + (j * offset))
                e.Graphics.DrawString(rs("Cap").Value, Font, Brushes.Black, X + 600, 60 + (j * offset))
                e.Graphics.DrawString(rs("Citta").Value, Font, Brushes.Black, X + 640, 60 + (j * offset))
                e.Graphics.DrawString(rs("Prov").Value, Font, Brushes.Black, X + 800, 60 + (j * offset))
                rs.MoveNext()

                j = j + 1
                e.HasMorePages = True

            Else
                j = j + 1
                e.HasMorePages = False
            End If
        Next i


    End Sub

    Private Sub PrintPreviewDialog1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintPreviewDialog1.Load

    End Sub
End Class
questo form gestisce la stampa di numerosi record circa 3000 impaginandoli secondo lo schema in una tabella 8*3, il problema che ho è il seguente: ogni volta che chiamo la routine di stampa (da quello che ho capito) l'evento e.HasMorePages = True fa una specie di chiamata ricorsiva alla funzione stessa creando una nuova pagina(gestione di più pagine). Ora, se faccio eseguire la query nella routine di stampa ad ogni nuova chiamata(con l'evento e.HasMorePages = True) rieseguo la query e stampo sempre gli stessi dati(generando un numero di pagine infinito)...se metto la query nel chiamante logicamente la printdocument1(nome della funzione) non me la vede mi da errore di "oggetto chiuso". esiste un modo per eseguire la query e rendere il resulset visibile in tutto il progetto.