Solved

Printing parameterised crystal reports direct to network printer

Posted on 2008-10-24
2
562 Views
Last Modified: 2012-06-27
Hi Experts

I have a VB.net windows app written in VS 2005. I have a viewer page with a report on it, and it works great, users click on a datagrid print icon and the report pops up.

This is my code for that:

    Private Sub cvwPatients_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cvwPatients.Load

        Dim PR As New PatientReferraldb
        Dim dt As DataTable = PR.SelectForPrint(valReferrL_ID) 'send in report id

        rdPatients.SetDataSource(dt)

        With cvwPatients
            .ReportSource = rdPatients
            .ShowTextSearchButton = False
            .ShowExportButton = False
            .DisplayGroupTree = False
            .ShowGroupTreeButton = False
        End With
    End Sub

What I need to be able to do is go to my database to get a list of records not printed, and loop through and print them without a print dialog popping up.

Any ideas on how I might do this, I've googled PrintToPrinter, and guess this is what I must be using, but I cant find any examples of selecting a network printer, or how to pass parameters similar to the way I've done it to display the report.

Andy
0
Comment
Question by:Andy Green
2 Comments
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 250 total points
ID: 22794728
0
 
LVL 3

Accepted Solution

by:
Andy Green earned 0 total points
ID: 22825939
I have got this working, in case anone else is looking to do a similar thing, this is how I did it.

Created a form with a CR Viewer called cvwPollReferals and a CR Report Document called rdPollReferrals.

I call the following function to print the report automatically.

    Private Sub DoPrint()

        Dim PR As New clsPatientReferraldb
        Dim dt As DataTable = PR.PollForPrint()

        For Each row As DataRow In dt.Rows

            Dim rPR As New clsPatientReferraldb
            Dim rdt As DataTable = PR.SelectForPrint(row("ReferL_RefNo")) 'send in report id

            rdPollReferrals.SetDataSource(rdt)
            rdPollReferrals.PrintOptions.PrinterName = txtPrinters.Text
            rdPollReferrals.PrintToPrinter(1, False, 0, 0)

            Dim UD As New clsPatientReferraldb
            UD.UpdatePostPrint(row("ReferL_RefNo"))
        Next
       End Sub

On the form I have a Printer selector populated with this code
    Private Sub ListAvailablePrinters()
        For Each strPrinterName As String In PrinterSettings.InstalledPrinters
            txtPrinters.Items.Add(strPrinterName)
        Next
        'Find the Default printer
        Dim PD As New PrintDocument
        txtPrinters.SelectedItem = PD.DefaultPageSettings.PrinterSettings.PrinterName
    End Sub

This came from emoreau's post so thank you for gewtting me started.

Andy
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Allow User To Arrange Columns At Datagridview 3 26
Get Client IP on RDS - VB.NET 15 46
.NET 2008 VB and C# 6 28
VB.net Progress Bar - Maximum Value too large 2 11
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question