Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing parameterised crystal reports direct to network printer

Posted on 2008-10-24
2
Medium Priority
?
568 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 1000 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

715 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