PDA

Click to See Complete Forum and Search --> : Crystal to show recordset


naruponk
Dec 13th, 2004, 10:17 PM
Hi, there

let's say i have created some recordset,
and i want to pass a parameter value to existing Crystal Report file.
like this ....

CRReport.Parameterfields.getitembyneame("test").addcurrentvalues "Test"

it works fine ...
but how can i give a parameter value as a recordset like this? :confused:

Fields1 Fields2
000001 AAAA
000002 BBBB
000003 CCC

or some thing like this ....
do while not rs.eof
crreport.parameterfields.getitembyname("test").addcurrentvalues rs.fields!X
rs.mmovnext
loop

Thanks for all help :)

RobDog888
Dec 13th, 2004, 10:35 PM
If you are just trying to pass a pre-created CR parameter...
Dim crxApp As CRAXDRT.Application
Dim oReport As CRAXDRT.Report

Set crxApp = New CRAXDRT.Application
Set oReport = crxApp.OpenReport(App.Path & "\MyReport", 1)
oReport.ParameterFields.Item(1).ClearCurrentValueAndRange
oReport.ParameterFields.Item(1).AddCurrentValue CStr(oRs!Name)
But it looks like you are trying to pass a recordset to a report? This will do it.
Option Explicit
'Add reference to Crystal Reports x.x ActiveX Designer RunTime Library
'Add reference to Crystal Reports Viewer Control
'Add reference to Microsoft ActiveX Data Objects 2.x Library
'oCnn = current open ADO connection object
Private Sub Command1_Click()

Dim oApp As CRAXDRT.Application
Dim oReport As CRAXDRT.Report
Dim oRs As ADODB.Recordset
Dim sSQL As String

sSQL = "SELECT * FROM Table1"
Set oRs = New ADODB.Recordset
Set oRs = oCnn.Execute(sSQL)
Set oApp = New CRAXDRT.Application
Set oReport = oApp.OpenReport(App.Path & "\MyReport.rpt", 1)
oReport.Database.SetDataSource oRs, 3, 1
crvMyCRViewer.ReportSource = oReport
crvMyCRViewer.ViewReport

End Sub

naruponk
Dec 14th, 2004, 08:48 PM
Thanks RobDog888. :)
Is this will automatically assign a fields in Crystal report?

RobDog888
Dec 14th, 2004, 09:11 PM
No, this will populate your already made report (bound/unbound fields). Say your
report has a Product Name textbox that is bound to a table's field Product_Name.
In you code that creates and populates the recordset, you select the same field
Product_Name and it will populate that control. The beuty of it is that your report
does not have to be connected to the database because the recordset is actually
the database.

naruponk
Dec 17th, 2004, 09:04 PM
Thanks a lot RobDog888 :thumb:

wizkid
Dec 13th, 2005, 10:18 AM
Hi,
i am new to crystal reports. and this thread helps me lot.
i want to pass a value as a parameter to crystal report which is selected in my vb application combo box.can i do this.If so please tell me.
i was created one crystal report with parameter StaffID.
which is a field in StaffDetails table. i want to pass the parameter StaffID from my vb application without prompting.
thanks a lot
wizkid

my code is :

Private Sub ViewReport_Click()
'Add reference to Crystal Reports x.x ActiveX Designer RunTime Library
'Add reference to Crystal Reports Viewer Control
'Add reference to Microsoft ActiveX Data Objects 2.x Library
'oCnn = current open ADO connection object


Dim oApp As CRAXDRT.Application
Dim oReport As CRAXDRT.Report
Dim oRs As ADODB.Recordset
Dim sSQL As String



sSQL = "SELECT * FROM StaffDetails"
Set oRs = New ADODB.Recordset
Set oRs = db_conn.Execute(sSQL)
Set oApp = New CRAXDRT.Application
Set oReport = oApp.OpenReport(App.Path & "\MyReport.rpt")
oReport.Database.SetDataSource oRs, 3, 1
crvMyCRViewer.ReportSource = oReport
crvMyCRViewer.ViewReport

Dim StaffID As CRAXDRT.ParameterFieldDefinitions
Dim cpar As CRAXDRT.ParameterFieldDefinition
oReport.EnableParameterPrompting = False

oReport.ParameterFields.GetItemByName("StaffID").AddCurrentValue "combo1.text"



End Sub


but it is giving some error message Invalid name.

wizkid
Jan 30th, 2006, 09:32 AM
Hi RobDog888,
please help me!!!
your code is working fine.
but my problem is..
i am not getting the select * from table query values on table
i was already created the report newreport.rpt.it is a blank report.
and i want the query result when i press command9 button.
nearly from 3 weeks i working on this report
please give me some solution :cry:

Private Sub Command9_Click()
Dim oreport As CRAXDRT.report
Dim oapp As CRAXDRT.Application
Dim oRs As Recordset
Dim sSQL As String

Set oRs = New Recordset
Set oRs = db_conn.Execute("SELECT * FROM table")
Set oapp = New CRAXDRT.Application
Set oreport = oapp.OpenReport(App.Path & "\newreport.rpt", 1)

oreport.Database.SetDataSource oRs, 3, 1

CRViewer91.ReportSource = oreport
CRViewer91.ViewReport
End sub

thank u