[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB6 and Crystal 9

Posted on 2006-05-23
8
Medium Priority
?
510 Views
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

Thanks

Shahzad
0
Comment
Question by:shahzadq
  • 6
  • 2
8 Comments
 
LVL 2

Accepted Solution

by:
AlThePal7 earned 2000 total points
ID: 16746313
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"
    conODBC.Open
'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).
    CrReport.DiscardSavedData
'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
    CRViewer1.ViewReport
    Do While CRViewer1.IsBusy
        DoEvents
    Loop

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

Author Comment

by:shahzadq
ID: 16746424
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...



Shahzad
0
 

Author Comment

by:shahzadq
ID: 16746505
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?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:AlThePal7
ID: 16746559
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.
0
 

Author Comment

by:shahzadq
ID: 16746594
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?
0
 

Author Comment

by:shahzadq
ID: 16746631
Can I specify in the code w/ADO, the server, regardless of if it's already setup in the .rpt file?
0
 

Author Comment

by:shahzadq
ID: 16746710
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)
0
 

Author Comment

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Suggested Courses
Course of the Month18 days, 21 hours left to enroll

834 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