On save, run crystal report and auto print

Posted on 2005-05-14
Last Modified: 2008-03-17
I have a simple form where users enter data.  When the user presses save, i need to run a crystal report (passing in the current order number), and automatically send to printer.  

One of the design requirements is for the report to print, without any intervention from the user.  (ie. the user does not have to hit enter key, or anything).

I am very familiar with Crystal reports, and a ok with However, I have never had to make the two work together.

If anyone could give me some ideas of where to begin, it would be greatly appreciated.
Question by:down0041
    LVL 13

    Assisted Solution

    Hi down0041,
    Check out the Crystal Reports SDK, they have some good samples on their website (also included in CR):
    It's really not hard, open, connect, print :)) (ok, just a bit more :))
    LVL 10

    Assisted Solution

    This is what I do. Basically, make sure you had a reference in your project to all libaries begining with "Crystal," there are a lot. I'm assuming you don't want a CrystalReportViewer, but just print it.

    All right, the first thing I usually do is create a DataSet (add to project, Dataset). In the schema designer, drag an "element" over, I call the very first one whatever I want the table to be called.  Then add entries, (make sure they are marked with "E") foir each Column you want in the query and make sure the datatype is right.

    Once you've done that, go and add a CrystalReport document to project. In the Field Source, or whatever it is called, click on the one that either says Project Data or ADO.NET. Then from there drill down until you find your dataset and insert it as a table, click next. If you know crystal reports then you know how to finish the report.

    Now, I don't know what your datasource is. I'm going to assume it is Access, if it is SQL then you will only need to do a Find&Replace between "OleDB" and "SQLClient." I'm assuming you haven't used ADO.NET, if I'm wrong then sorry.

    First add an imports statement:
    imports System.Data.OleDB

    Now in whatever function or whatever place you create this report use code similar to this:

    Dim oConn As New OleDBConnection(" .. This is your connection string, make sure it is right")
    Dim oCmd As New OleDBCommand
    oCmd.Connection = oConn

    Dim ds As New MyDataSet   ''' This is actually whatever you named your Dataset's .xsd file earlier
    Dim oAdapter As New OleDBDataAdapter(oCmd)

    oAdapter.Fill(ds, "MyDataSetTable")  '' Whatever you named the table in the DataSet, probably same as MyDataSet

    Dim rpt As New CrystalReport1 '' This is the same as whatever your report document's name is

    Now, you can do whatever you want with it, print it or put it in a report or what have you. Hope this helps.
    LVL 100

    Accepted Solution


    Author Comment

    Thank you.  All the above comments were helpful.  

    For the quick printing (without showing a dialog box), the real secret seems to lie in creating the reportDocument object.  From there, you can call the method "printToPrinter".  

    For linking my orderID to the report, the secret seems to lie in
    Me.CrystalReportViewer1.SelectionFormula = "{ORDERS.TKT_NO} = '" & fldOrderID.Text & "'"

    Thanks again for all your input.
    LVL 100

    Expert Comment

    Glad i could help


    Featured Post

    Courses: Start Training Online With Pros, Today

    Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

    Join & Write a Comment

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    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 …
    This video discusses moving either the default database or any database to a new volume.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    746 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

    14 Experts available now in Live!

    Get 1:1 Help Now