Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using ADO Recordset to Connect to Crystal Report

Status
Not open for further replies.

BigQuincy

Programmer
Dec 12, 2001
16
US
I have read all the posts I can find on this subject. I keep getting a SUBSCRIPT OUT OF RANGE error from VB on the SetDataSource line below. Using examples from this forum, I have tried the following code:

Private Sub cmdCrystalTest_Click()

Dim rptTest As New CrystalReport1

'rsData is a an ADO recordset that is valid and contains data

rptTest.Database.SetDataSource rsData

CRViewer1.ReportSource = rptTest
CRViewer1.Refresh

End Sub

All I want to do is connect to a live Recordset and display the contents of the recordset on the report.
I am using Crystal Reports 8.5 and Visual Basic 6.0

Thanks!!!
 
OK, I found the fix to the problem above using

rptTest.Database.Tables.Add "", , rsData, , "p2smon.dll"
rptTest.Database.SetDataSource rsData, 3, 1

(Thanks to whoever posted that fix!!)


So I am not getting the subscript error anymore. Now however, when the Viewer displays, it is empty. My recordset is not displaying. Any ideas??
 
For this purpose Use RDC
The Crystal Reports Report Design Component(RDC) is an in-process ActiveX DLL based on the Component Object Model (COM). Crystal Reports RDC satisfies all of your dynamic reporting needs.
Technical Support reference to the RDC examples contained in the downloadable file ASPXMPS85.exe that you will found on Crystal Decision web site

First create your report on DAta source Active Data(Field definition)or (.ttx)

then write these code in VB

'Creating an Application Object
Set CRPapp = CreateObject("Crystal.CRPE.Application")
'Create Report object
Set CRPreport = CRPapp.OpenReport("ReportNameWithPAth.rpt")
'Create Report database object
Set crpDatabase = CRPreport.Database
'Create report database table collections object
Set crpDatabaseTables = crpDatabase.Tables
'Create table object
Set crpDatabaseTable = crpDatabaseTables.Item(1)
'Create your Recordset in VB like rs
'Assign your recordset rs to table object
crpDatabaseTable.SetPrivateData 3, rs
'Set report selection formula"
CRPreport.RecordSelectionFormula = "Your select formula if any"
'Sort your report on any field
CRPreport.RecordSortFields.Add Asc/dec, fieldName
CRPreport.ReadRecords
'to display report on screen
CRPreport.Preview Title, Left, Top, Width, Height, style, parentwindow


For more detail read Crrdc.hlp file that you find in your machine at this location c:\Frogram File\Seagate Software\Report Designer Component\crrdc.hlp
 
Hi guys,

I had that same subscript error (I'm using RDC 8) VB & SQL Server 7. I tried all the advice and some of it worked and some did not, I had some additional errors no one else mentioned.

Anyway, if you are wanting a solution for passing an ADO recordset to a RDC blank report with unbound fields, the below code works super and it's only actually 2 lines of code that I used to do it. Check it out.

Dean Kuntz

--------------- snip ----------------------------------

Private Sub Form_Load()
Screen.MousePointer = vbHourglass
'---------------------------------------------
' code above generated by RDC
'---------------------------------------------

Dim Conn As New ADODB.Connection
Dim Cmd As New ADODB.Command
'---------------------------------------------
' connect to SQL Server (the cnnStr is an
' example to connect to the desktop version)
'---------------------------------------------
With Conn
.ConnectionString = "DRIVER={SQL Server};SERVER=sn;DATABASE=dbn;uid;pw"
.Open
End With
'---------------------------------------------
' obvious
'---------------------------------------------
With Cmd
.CommandText = "select companyname, city from customers"
End With

'---------------------------------------------
' now this is the part where we all had grief
'---------------------------------------------

'---------------------------------------------
' pass the connection and command objects
' to the report
'---------------------------------------------
Report.Database.AddADOCommand Conn, Cmd
'---------------------------------------------
' auto dynam bind the fields to the two
' unbound fields I defined on the report
' with the RDC (don't forget to name the
' unbound fields the same as the selected
' fields if you use the crBMTName param)
'---------------------------------------------
Report.AutoSetUnboundFieldSource crBMTName

'---------------------------------------------
' code below generated by RDC
'---------------------------------------------
CRViewer1.ReportSource = Report
CRViewer1.ViewReport
Screen.MousePointer = vbDefault
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top