Solved

Link Crystal Report to a VB6 ADO recordset, run report from vb6

Posted on 2006-07-17
17
1,904 Views
Last Modified: 2008-01-09
I'd like to run some Crystal Reports directly from ADO recordsets in my VB6 application, but I don't know if it's possible, or the syntax to use. The data is in Oracle, and I use the recordsets in Grids on by VB forms. Thank you.
0
Comment
Question by:briankam
  • 6
  • 4
  • 3
  • +1
17 Comments
 
LVL 5

Expert Comment

by:dkDeveloper
ID: 17124591
Hi briankam,

Have you tried something like this...

crxReport.Database.SetDataSource [ADO_RECORDSET_VAR]


Cheers!
dK
0
 

Author Comment

by:briankam
ID: 17124899
I tried:       Form1.CrystalReport1.Database.SetDataSource [rsReport_Query],
where rsReport_Query is defined with:
Public rsReport_Query As ADODB.Recordset
Set rsReport_Query = New recordset
rsReport_Query.Open "Select ... From ...",
but the CrystalReport1 control doesn't have a .Database property (to program errored to "Object doesn't support this property or method").
I'm trying to run the report with the command:
Form1.CrystalReport1.Action = 1
which displays Crystal in its own window, not a report viewer window (on a form). Thank you.

0
 
LVL 5

Expert Comment

by:dkDeveloper
ID: 17124930
Hi dkDeveloper,

What version of CR are you using?

dK
0
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.

 

Author Comment

by:briankam
ID: 17125105
Let me clarify:
In looking at older code, I see that I did just what you suggested, and it worked if I viewed the report in a Crystal Report Viewer Window on a VB6 form, using:
Dim Report As CRAXDRT.Report
Set Report = crystal.OpenReport("C:\appdir\...\Report_A.rpt")
Report.Database.SetDataSource rsReport_Query
CRViewer1.ReportSource = Report
CRViewer1.ViewReport

But I had no luck exporting data from in that scenario. So I'm trying to set the report's data source with the Crystal Report control (CrystalReport1) to the ADO recordset, and then call it with:
Me.CrystalReport1.ReportFileName = "C:\appdir\...\ReportA.rpt"
Me.CrystalReport1.Action = 1

but I don't see such a property on the Crystal Report Control.
Thanks again,
0
 
LVL 5

Expert Comment

by:dkDeveloper
ID: 17125323
Hi briankam,

Stabbing in the dark again here but what about this...

Dim Report As CRAXDRT.Report
Set Report = crystal.OpenReport("C:\appdir\...\Report_A.rpt")
Report.Database.SetDataSource rsReport_Query
CRViewer1.ReportSource = Report
Me.CrystalReport1.Action = 1

Good Luck!
dK
0
 

Author Comment

by:briankam
ID: 17125561
Thanks dK,

I'm using CR v. 8.5 with VB6.

How should I define the 'crystal' you use in the 2nd line? When I initialized crystal with:

Public crystal As CRAXDRT.Application

I got an error on the set report = crystal.OpenReport("C:\...\Report_A.rpt"): Method or data member not found.

Thanks again,
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 17126944
Are you using the RDC or the OCX?

The suggestions being made are for use with the RDC (CRAXDRT.DLL)

Your code seems to be for the OCX (crystl32.ocx)

I suggest you remove the OCX references and add the Crystal references and the Crystal RDC Viewer.

The OCX was dropped in CR9 and later versions so if you plan to upgrade in the future you will have to change your method.

mlmcc
0
 

Author Comment

by:briankam
ID: 17129249
Thanks mlmcc,

I need to look into the things you mention, as I'm not familiar yet with them.
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 500 total points
ID: 17134580
Here is a link to help migrate from the OCX to the RDC
http://support.businessobjects.com/communityCS/TechnicalPapers/scr8-ocxtordc.pdf.asp

mlmcc
0
 
LVL 6

Expert Comment

by:AHMKC1
ID: 17137224
if you use Crystal Report control, create a report from CR then try

CrystalReport1.ReportFileName=Your report File Path
CrystalReport1.Action=1

if you use Crystal Report Viewer control i.e. OCX then

Design a report in your vb CR Designer and then try it
place a report veiwer control on form and write following code at load events

Dim Rpt As Report
Dim Rs As Recordset

Set Rs = New Recordset
Set Rpt = New ReportName
Rs.Open "SELECT * FROM TableName", Cnn, adOpenStatic, adLockOptimistic   ***** Where cnn is your Connection String
Rpt.Database.SetDataSource Rs, 3, 1

CRViewer1.ReportSource = Rpt
CRViewer1.ViewReport
CRViewer1.Zoom (100)
0
 

Author Comment

by:briankam
ID: 17137822
Thanks AHMKC1,

I have actually done both of the methods you mentioned. My final goal is to assign my ADO recordset as the source of the RDC report -- the first method you show (which will enable me to put all my filter logic in the VB code that generates the recordset). Thanks for any further help you can give.
0
 
LVL 6

Expert Comment

by:AHMKC1
ID: 17138071
for filtering your data use Report Parameter

Create parameter in your report file on basis of your filtered field  (like  paramID)

Then on your form write follwing code

CrystalReport1.ReportFileName=Your report File Path
CrystalReport1.ParameterField(0)="ParamID;"& textID.Text & ";True"
CrystalReport1.Action=1

thanks
0
 

Author Comment

by:briankam
ID: 17496937
Thanks mlmcc, and I'm sorry I let the question lapse. What happened was that I upgraded to Crystal version 11, and I can set the ADO recordset as the datasource with: "      CrystalReport.Database.SetDataSource rsReport_Query", and can export while viewing in report viewer. So the solution was to upgrade.

All the comments were helpful though, to lead me there, but there wasn't a definitive solution.
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 17499339
If a particular comment was helpful you can accept it with a B grade.  That is essentially what B means.  The comment led you to the solution.

mlmcc
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 17507539
Glad i could help

mlmcc
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

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

733 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