Results 1 to 3 of 3

Thread: Showing Report in Viewer

  1. #1
    Guest

    Unhappy

    In my application I have added a Form on which I placed a CrystalReport-control and a CRViewer-control. I want all my reports to be shown on this Form. It's an MDIChild so it forms a group with the rest of the application.

    I have to following code to show the report, but I don't get the viewer filled.

    CrystalReport.ReportFileName = "D:\Report.rpt"
    frmProef.CryRapport.SetTablePrivateData 0, 3, rs.DataSource
    CrViewer.ReportSource = ''''HELP I DON'T KNOW HOW TO FIL THE SOURCE!!!!''''
    CrViewer.ViewReport
    CrViewer.Show

  2. #2
    Guest

    Wink

    You don't need to add a crviewer to show your report if you
    have made it in advance.
    You just need to give the connection to the DB

    CrystalReport.Connect = "DSN = ; UID = ; PWD = ;DSQ = ''"
    CrystalReport.SQLQuery = query you've made your report with

    Optional if you like to change the where clause you can give a new query to the control

    crptObjec.PrintReport

  3. #3
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    Using Crystal Report control (OCX) is absolete, according to Seagate Software. Use Crystal Viewer instead.

    Your variables for Application, Report and Recordset objects should be global. Here is a little example on how to use ADO recordset to show the report in the Viewer
    Add references to the following:


    Microsoft ActiveX Data Objects Library
    Crystal Report ActiveX Designer Run Time Library


    Code:
    Option Explicit
    Private m_objRS As New ADODB.Recordset
    Private m_objReport As CRAXDRT.Report
    Private m_objApp As New CRAXDRT.Application
    
    Private Sub Command1_Click()
        Dim cn As New ADODB.Connection
        Dim strSQL As String
        
        cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Program Files\VB98\NWIND.MDB"
        
        strSQL = "Select * From Customers"
        
        m_objRS.CursorLocation = adUseClient
        m_objRS.Open strSQL, cn, adOpenStatic
        
        Set m_objReport = m_objApp.OpenReport("F:\MyReport.rpt", 1)
        With m_objReport
            .Database.SetDataSource m_objRS, 3, 1
            .DiscardSavedData
            .ReadRecords
        End With
        
        With CRViewer1
            .ReportSource = m_objReport
            .ViewReport
        End With
        
        m_objRS.Close
        Set m_objRS = Nothing
        
        cn.Close
        Set cn = Nothing
        Set m_objReport = Nothing
        Set m_objApp = Nothing
    End Sub
    In this example I'm using Northwind database that comes with VB.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width