Solved

Printing parameterised crystal reports direct to network printer

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

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now