VB6 and Crystal 9

Posted on 2006-05-23
Last Modified: 2008-03-06
Hi all,

I know there's a million thread about Crystal and VB6 trying to run it, but they all have such slightly different nuances in the answers, depending on the version of vb, and crystal, and etc. etc.

Maybe someone can help me.

I have an .rpt file

Now, I have no clue what to do from here.  Tried playing with some of the controls, but they all seem to do nothing...

Where do I got from the beginning?

For the project I am using VB6, Crystal 9


Question by:shahzadq
    LVL 2

    Accepted Solution

    Hi Shahzad,

    First you should include a reference to the Crystal Report Viewer Control (crviewer.dll) in your project and draw a Viewer on a form.  The following code shows how to display the report in the Viewer.  It also includes passing data to a report using ADO - you may need to do this, you may not, it depends how your report is set up:

    Dim conODBC As ADODB.Connection
    Dim adoRS As ADODB.Recordset
    Dim CrApplication As CRAXDRT.Application
    Dim CrReport As CRAXDRT.Report

    'Construct the SQL query.
        strSQL = "SELECT * FROM Test WHERE Number=1"

    'Open connection to database.
        Set conODBC = New ADODB.Connection
        conODBC.ConnectionString = "DRIVER={MySQL ODBC 3.51 Driver};" _
                                 & " SERVER=TestServer1;" _
                                 & " DATABASE=TestDatabase1;" _
                                 & " UID=root;PWD=; OPTION=35"
    'Create ADO Recordset Object.
        Set adoRS = New ADODB.Recordset
    'Run the query.
        adoRS.Open strSQL, conODBC, adOpenForwardOnly, adLockReadOnly, adCmdText

    'Create the Crystal Reports application object.
        Set CrApplication = New CRAXDRT.Application
    'Create the Crystal Reports report object.
        Set CrReport = New CRAXDRT.Report
    'Select the correct Crystal report.
        Set CrReport = CrApplication.OpenReport("C:\Temp\TestReport.rpt")
    'Make sure the report doesn't contain saved data (may not need this).
    'Pass the recordset containing the data to the report - the report has to be set
    'to use an ADO data source, not just ODBC (may not need this).
        CrReport.Database.SetDataSource adoRS

    'Use the Crystal Reports viewer control to view the report.
        CRViewer1.ReportSource = CrReport
        Do While CRViewer1.IsBusy

    'Release the memory user by the Crystal Reports objects.
        Set CrReport = Nothing
        Set CrApplication = Nothing
    'Destroy recordset object and close the database.
        Set adoRS = Nothing
        Set conODBC = Nothing

    Author Comment

    OK Cool, thanks...  I'm a little further along now...  What I'm not sure about (since I was just handed these report, I know nothing about how they're created) is that I understand the ODBC and all that is already put into the .rpt file...   If this is the case, do I still need to do the connection part of the code in VB?  If so, then I'm assuming I have to have the exact same settings...

    Also I'd think the SQL is also built into the .rpt file...

    I did that above code w/out the data connection parts of the code, and (of course!) I get the ODBC connection error...


    Author Comment

    Would these be the issue, that do I have to have the same ODBC connection with the same DSN name setup on my machine, as was setup on the machine where the report was created?
    LVL 2

    Expert Comment

    In short, yes.  It is through this DSN that CR can connect to the correct database and get the required data.  That is one of the reasons I like using ADO, as you have more control over what data goes to the report.

    Author Comment

    Right I see.  So then to clarify what I think I need to do...  I can make the ODBC in windows admin setup the same connection, but do I have to give it the same DSN name?

    If I'm using the DSN and not ADO, how would I specify the DSN in the code?  With the connection string?

    Author Comment

    Can I specify in the code w/ADO, the server, regardless of if it's already setup in the .rpt file?

    Author Comment

    Hey!  Seems to be almost working ok...  only thing I get now is the message "Not Supported" when it tries to load (All the DB errors are gone, I set up the DSN name and put the DSN name into the code)

    Author Comment

    Thanks!  Eventually with some modifying and tweaking, your help with the specific code did me wonders. :)

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Introduction This article makes the case for using two modules in your VBA/VB6 applications to provide both case-sensitive and case-insensitive text comparison operations.  Recently, I solved an EE question using the LIKE function.  In order for th…
    Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    730 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

    19 Experts available now in Live!

    Get 1:1 Help Now