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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Pass a recordset from VB to CR report with multi-table

Status
Not open for further replies.

hlac

Programmer
Nov 20, 2001
7
CA
Hi, I am new to Crystal Reprots...please help!!!

I've created a report using 3 tables (customer, Region and country) - they are linked the Ids. Within my VB application, I've created to a recordset that is based on the customer table and i want to pass this to my CR report to generate a report.

 
The report has to be created using the active data driver. Then the fields used in the report are considered one 'virtual' table. Create a recordset that contains these same fields, in the same order, and pass it using a "SetPrivateData" command. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
thank you for your help. Is there an alternative solution for passing data from VB to a multi-table report?
 
How else are you storing the data in VB? Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Hi Ken,

I am using MS SQL 2000 for the backend and am working with a 3-tier vb app. The customer table has the following data structure: CustomerId, CustomerName, CustAddress, City, State, RegionId, CountryId...

Below is the code for creating a recordset based on a userdefined filter string and passing it to the Report

'****** Form #1 ***********
Public Sub DoPrint()
Dim strReportName As String
Dim rs As Recordset
Dim cRsFactory As clsRsFactory

If mfStdPrint Is Nothing Then
Set mfStdPrint = New fStdPrint
End If

mfStdPrint.Show vbModal

If mbPrint Then
If mfViewReport Is Nothing Then
Set mfViewReport = New fViewReport
End If

strReportName = App.Path "AgentReport.rpt"

'get recordset based on filter
mstrFilter = "CITY LIKE 'Los Angeles' AND StateProvince LIKE 'CA' AND Inactive=0"

Set cRsFactory = New clsRsFactory
Set rs = cRsFactory.Create(eRsAgent, mstrFilter)

'open report viewer - call form #2
Call mfViewReport.OpenReport(strReportName, rs)
End If
End Sub

'****** Form #2 ***********

Private crApplication As New CRAXDDRT.Application
Private crReport As CRAXDDRT.Report

Private Sub Form_Load()
'specify the report to preview
CRViewer.ReportSource = crReport
'View the Report
CRViewer.ViewReport
End Sub

Public Sub OpenReport(ByVal strReportName As String, ByVal rs As Recordset)

If rs.RecordCount < 1 Then
MsgBox &quot;No data to print.&quot;
Exit Sub
End If

Set crReport = crApplication.OpenReport(strReportName)

'Pass a recordset into a report at rum-time
'the report was created with Active Data Driver

crReport.DiscardSavedData

'pass recordset to report
crReport.Database.SetDataSource rs, 3
End Sub

The key functinality here is to print a report that consist of only filtered data. How do I implement a alternative solution with what i have here?
 
If you have a recordset in memory, there is only onle way to pass it. The RDC uses the SetDataSource command, which you seem to be using correctly. If the recordset has only filtered data in it, that is all that should go to the report.

I can't evaluate your code for building the recordset. What behavior are you getting? Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
My recordset is working fine - I am getting correct data back from it. my code works fine when the report has only one table (i.e. Customer) but not multi-table. &quot;Database file not found&quot; is the error i am getting when calling the multi-table report from VB. What does TTX file do?
 
piggy13, are you hlac under a different name?

You can't pass a recordset to a 'multi-table' report, unless the report's tables were linked together using the active data driver when the report was created. The TTX is a set of field definitions that can substitute for a recordset during design time. Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guide to using Crystal in VB
tek@kenhamady.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top