Solved

Printing parameterised crystal reports direct to network printer

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
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…

617 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