Solved

Printing parameterised crystal reports direct to network printer

Posted on 2008-10-24
2
563 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 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