print crystal report selected printer

dushantha

New member
Joined
Jan 19, 2021
Messages
2
Programming Experience
Beginner
hi ,

i'm using this code for the print crystal report but always print in default printer
i can't understand why

print crystal report:
    Private Sub btnstampa_Click(sender As Object, e As EventArgs) Handles btnstampa.Click
        Try

            Dim cryRpt As New ReportDocument
            Dim crtableLogoninfos As New TableLogOnInfos
            Dim crtableLogoninfo As New TableLogOnInfo
            Dim crConnectionInfo As New ConnectionInfo
            Dim CrTables As Tables
            Dim CrTable As Table


            cryRpt.Load("C:\Gestione Magazzino\Report\rpt_etichetta_daspedire.rpt")
            With crConnectionInfo
                .ServerName = My.Settings.mServer
                .DatabaseName = My.Settings.mDBname
                .UserID = My.Settings.mUsername
                .Password = My.Settings.mPassword
            End With
            CrTables = cryRpt.Database.Tables
            For Each CrTable In CrTables
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
            Next
            cryRpt.Load("C:\Gestione Magazzino\Report\rpt_etichetta_daspedire.rpt")
            CrystalReportViewer1.ReportSource = cryRpt
            CrystalReportViewer1.SelectionFormula = "{DaSpedire.codicespedizione}='" & txtcodspedizione.Text.ToString() & "'"
            CrystalReportViewer1.Refresh()
            CrystalReportViewer1.RefreshReport()

            cryRpt.PrintOptions.PrinterName = txtstampante.Text.ToString()
            cryRpt.PrintToPrinter(txtcopie.Text, False, 0, 0)

        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub
 

Latest posts

Back
Top