[RESOLVED] Crystal Reports 9.2 and Stored Procedures problem
Hi, before making my question, I'm working with:
VB6
Crystal Reports 9.2.2.693
SQL Server
I need to connect via OLEDB
Ok, I have setup my report all from within the report. The database, the stored procedure, and the fields I'm going to display.
My question is: How can I do to display the report by passing the parameters through VB6?
I already have added Crystal Reports 9 ActiveX Designer RunTime Library and Crystal Reports Viewer 9 to References as well as Crystal Report Viewer 9 to Components.
Hope you can help me figure this out.
Marcelo.
Re: Crystal Reports 9.2 and Stored Procedures problem
Use the CRAXDRT objects to set the parameters (and anything else you need, like login information).
This sample code Opens, Sets two Parameters and then Shows the report on a Form that contains the Crystal Viewer control. In this case the two parameters are "Discrete" Date values that the user chosen from Date Picker controls.
VB Code:
Dim objCrystal As CRAXDRT.Application 'its better to create this object global to the VB application.
Dim objReport As CRAXDRT.Report
Dim objParam As CRAXDRT.ParameterFieldDefinition
Set objCrystal = New CRAXDRT.Application
Set objReport = objCrystal.OpenReport(FileName, 1)
Set objParam = objReport.ParameterFields.GetItemByName("@FromDate")
objParam.ClearCurrentValueAndRange
objParam.AddCurrentValue dtpFromDate.Value
Set objParam = objReport.ParameterFields.GetItemByName("@ToDate")
objParam.ClearCurrentValueAndRange
objParam.AddCurrentValue dtpToDate.Value
With frmReportViewer
If Len(ReportTitle) > 0 Then
.Caption = ReportTitle
End If
.ReportViewer.ReportSource = objReport
.ReportViewer.ViewReport
.Show
.ZOrder vbBringToFront
End With
Note I only have Crystal 8.5 but the code should be similar for 9.
Re: Crystal Reports 9.2 and Stored Procedures problem
Hi Bruce, I'm trying to figure out your code. And I think that is for filling a report indicating field and value, right?
But... I already have all parameters setup at the file.rpt report such as database connection, stored procedure (which has a big sql query) and of course the fields resulting from that stored procedure which are set at the report designer.
This stored procedure accepts two parameters which has nothing to do with fields. They are numeric and they act as follows: if prm1=0 and prm2=0 then do something; if prm1=0 and prm2=1 then do something else... and so on...
Hope you understand me and can help me figure this out.
Thanks, Marcelo.
Re: Crystal Reports 9.2 and Stored Procedures problem
My code shows you how to pass parameter values from a VB 6 application to the Crystal Report and then show the report.
The Report.ParameterFields collection is used to set the value of the parameters that you created in your rpt file.
When the line .ReportViewer.ViewReport is called the Crystal Runtime library takes over and the report is generated.
Re: Crystal Reports 9.2 and Stored Procedures problem