briankam
asked on
Link Crystal Report to a VB6 ADO recordset, run report from vb6
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.
ASKER
I tried: Form1.CrystalReport1.Datab ase.SetDat aSource [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.Actio n = 1
which displays Crystal in its own window, not a report viewer window (on a form). Thank you.
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.Actio
which displays Crystal in its own window, not a report viewer window (on a form). Thank you.
Hi dkDeveloper,
What version of CR are you using?
dK
What version of CR are you using?
dK
ASKER
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:\app dir\...\Re port_A.rpt ")
Report.Database.SetDataSou rce 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.ReportFi leName = "C:\appdir\...\ReportA.rpt "
Me.CrystalReport1.Action = 1
but I don't see such a property on the Crystal Report Control.
Thanks again,
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:\app
Report.Database.SetDataSou
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.ReportFi
Me.CrystalReport1.Action = 1
but I don't see such a property on the Crystal Report Control.
Thanks again,
Hi briankam,
Stabbing in the dark again here but what about this...
Dim Report As CRAXDRT.Report
Set Report = crystal.OpenReport("C:\app dir\...\Re port_A.rpt ")
Report.Database.SetDataSou rce rsReport_Query
CRViewer1.ReportSource = Report
Me.CrystalReport1.Action = 1
Good Luck!
dK
Stabbing in the dark again here but what about this...
Dim Report As CRAXDRT.Report
Set Report = crystal.OpenReport("C:\app
Report.Database.SetDataSou
CRViewer1.ReportSource = Report
Me.CrystalReport1.Action = 1
Good Luck!
dK
ASKER
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,
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:\...
Thanks again,
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
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
ASKER
Thanks mlmcc,
I need to look into the things you mention, as I'm not familiar yet with them.
I need to look into the things you mention, as I'm not familiar yet with them.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if you use Crystal Report control, create a report from CR then try
CrystalReport1.ReportFileN ame=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)
CrystalReport1.ReportFileN
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
CRViewer1.ReportSource = Rpt
CRViewer1.ViewReport
CRViewer1.Zoom (100)
ASKER
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.
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.
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.ReportFileN ame=Your report File Path
CrystalReport1.ParameterFi eld(0)="Pa ramID;"& textID.Text & ";True"
CrystalReport1.Action=1
thanks
Create parameter in your report file on basis of your filtered field (like paramID)
Then on your form write follwing code
CrystalReport1.ReportFileN
CrystalReport1.ParameterFi
CrystalReport1.Action=1
thanks
ASKER
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.Set DataSource 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.
All the comments were helpful though, to lead me there, but there wasn't a definitive solution.
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
mlmcc
Glad i could help
mlmcc
mlmcc
Have you tried something like this...
crxReport.Database.SetData
Cheers!
dK