Click here to Skip to main content
15,921,212 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to call crystal report using print button
and how to combine or add sub report on crystal report
and how to export them as one application

What I have tried:

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        Dim cryRpt As New ReportDocument
        Dim crtableLogoninfos As New TableLogOnInfos
        Dim crtableLogoninfo As New TableLogOnInfo
        Dim crConnectionInfo As New ConnectionInfo
        Dim CrTables As Tables
        Dim CrTable As Table

        cryRpt.Load("PUT CRYSTAL REPORT PATH HERE\CrystalReport1.rpt")

        With crConnectionInfo
            .ServerName = "YOUR SERVER NAME"
            .DatabaseName = "YOUR DATABASE NAME"
            .UserID = "YOUR DATABASE USERNAME"
            .Password = "YOUR DATABASE PASSWORD"
        End With

        CrTables = cryRpt.Database.Tables
        For Each CrTable In CrTables
            crtableLogoninfo = CrTable.LogOnInfo
            crtableLogoninfo.ConnectionInfo = crConnectionInfo

        CrystalReportViewer1.ReportSource = cryRpt
    End Sub

i am using ms access as database
Updated 13-Jul-20 21:17pm

1 solution

Q1) How to print CR directly to printer -

refer THIS link.

Dim cryRpt As ReportDocument = New ReportDocument()
        CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.Pdf

        cryRpt.PrintToPrinter(1, False, 0, 0)

You could also use -
<form id="form1" runat="server">
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />

with code behind -
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim cryRpt As ReportDocument = New ReportDocument()
        CrystalReportViewer1.ReportSource = cryRpt

        CrystalReportViewer1.PrintMode = CrystalDecisions.Web.PrintMode.Pdf

Q2) Combine 2 reports -
Approach 1 : Use sub-report :- If you have a common parameter between both the report, then best approach to this is to use one report as a sub-report and second will treat as a main report. For this in main report, Insert -> Sub-report, map both reports and execute will give the desire result.

See how to combine 2 crystal reports to 1 crystal reports for more details.

Q3)How to export report - Make use of the PDF function to export.
Share this answer
Beginner213456 20-Jul-20 20:29pm    
Can you still use the subreport when you try to create different designs on the report?
and where can i find the crystalreportviewer in the toolbox, i searched in the reporting tab in the toolbox but the pointer and report viewer is present.
than you for your reply

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900