Crystal Reports XI Connection in Visual Basic

Posted on 2007-07-24
Last Modified: 2012-08-14
I am struggling to find a way to display my reports within Visual Basic 6 on a form. Reports are based on Microsoft SQL Server 2005 stored procedures.

I have the Crystal ActiveX Report Viewer Library 11 and the Crystal Reports ActiveX Runtime Library 11 added to my project. I have added the control to a form and declared the following:

Dim CRReport As New craxdrt.Report
Dim CRApp As New craxdrt.Application

I don't know where to go from here to display the report passing parameters.

Can anybody help.
Question by:chunnster
    LVL 6

    Expert Comment

    If you're new to this, try using the wizard.

    1. Go to Project >> Components >> Designers, you should see an object named Crystal Reports 11, make sure it is checked.
    2. Now go to Projects >> Add Crystal Reports 11, and the wizard should appear.
    3. Choose the alternative that suits you best, and follow the wizard.
    4. Study the code that was generated by the wizard.
    LVL 4

    Expert Comment

    LVL 6

    Expert Comment

    The Wizard creates a CrystalReport object. Modify the RecordSelectionFormula property of this object to supply parameters and limit results. Try doing a search for RecordSelectionFormula.
    LVL 84

    Accepted Solution

    Function LoadReport(ReportName As String) As Boolean

      ' Project    :       PLB
      ' Procedure  :       LoadReport
      ' Description:       loads a report in the viewer
      ' Created by :       Project Administrator
      ' Machine    :       SCOTTS
      ' Date-Time  :       5/25/2005-09:39:04
      ' Parameters :       ReportName (String): the full path, including name and extension, of the report

      Dim crxApp      As New CRAXDRT.Application
      Dim crxRpt      As CRAXDRT.Report
      On Error GoTo Err_LoadReport
      Screen.MousePointer = vbHourglass
      Set crxRpt = crxApp.OpenReport(ReportName)
      ctlCrystalViewer.ReportSource = crxRpt
      ctlCrystalViewer.DisplayToolbar = False
      On Error Resume Next
      Set crxApp = Nothing
      Set crxRpt = Nothing
      Screen.MousePointer = vbDefault
      Exit Function

      Select Case Err
        Case Else
          MsgBox Err & ":" & Error$, vbCritical, "frmReportViewer" & ": " & "LoadReport"
      End Select

      Resume Exit_LoadReport

    End Function

    ctlCrystalViewer is the CrystalActiveXReportViewer on the form ...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    794 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

    16 Experts available now in Live!

    Get 1:1 Help Now