Link to home
Start Free TrialLog in
Avatar of rhubarbtwo
rhubarbtwo

asked on

Passing an adoRS to an active report in CR8

I'm trying to pass an ado recordset to a report which has fields from an associated data definition
ttx file.

I've made the following declarations in my code:

Public adoCon As New ADODB.Connection
Public adoRS As New ADODB.Recordset
Public crpApp As CRAXDRT.Application
Public crpReport As CRAXDRT.Report
Dim sDocPath As String

I've opened an ado con and an ado rs then....

sDocPath = App.Path & "\report1.rpt"

Set crpApp = New CRAXDRT.Application
'OR Set crpApp = CreateObject("CrystalRuntime.Application")

'Set crpReport = New CRAXDRT.Report '=> illegal op

Set crpReport = crpApp.OpenReport(sDocPath)

crpReport.Database.Tables(1).SetDataSource adoRS, 3
'OR crpReport.Database.Tables.Item(1).SetDataSource adoRS, 3

crpReport.ReadRecords

Load Form1

With Form1
.CRViewer1.ReportSource = crpReport
.CRViewer1.ViewReport
.Show
End With


But all I get in the report at runtime is the one line of sample data in the ttx file.

If I remove the comment from set crpReport = new CRAXDRT then vb causes an illegal op and crashes.

A sample on Planet Source Code uses a Crystal Designer instead of a CRAXDRT.Report. For some reason

I can get this sample code to display my adoRS data in the viewer using my rpt which is linked to a
ttx, but not using the above code. So there can't be too much wrong with my report and ttx file.

The CR Developer help for SetDataSource says that the SetDataSource method can be invoked only in formatting Idle mode, I was wondering if this had anything to do with the problem.

I'm sure the problem must be a simple one, the code seems to be ok when compared with other examples, is there a setting I've missed?

Can anyone email me a simple working sample vb project using CR version 8?
Avatar of DRRYAN3
DRRYAN3

rhubarbtwo

In keeping with the philosophy of EE, here is the VB code and the TTX file filling your request.  If you post your email address I will send you a zip file containing the VB project, TTX file, .RPT file and the database.

Public adoCon As New ADODB.Connection
Public adoRS As New ADODB.Recordset
Public crpApp As CRAXDRT.Application
Public crpReport As CRAXDRT.Report
Dim sDBPath As String
Dim sDocPath As String

Private Sub Command1_Click()
  Unload Me
End Sub

Private Sub Command2_Click()
  Dim strSQL As String
  strSQL = "select orders.[Order ID] as OrderID, " & _
           "orders.[Order Date] as OrderDate, " & _
           "orders.[Customer ID] as CustID, " & _
           "[orders detail].[product id] as ProductID, " & _
           "[orders detail].[unit price] as UnitPrice, " & _
           "[orders detail].[quantity] as Quantity, " & _
           "product.[product name] as ProductName " & _
           "from orders left join " & _
           "([orders detail] left join [product] on " & _
           "[orders detail].[product id] = [product].[product id]) " & _
           "on orders.[order id] = [orders detail].[order id];"
           
  adoRS.Open strSQL, adoCon, adOpenForwardOnly, adLockReadOnly
  Set crpReport = crpApp.OpenReport(sDocPath)
  crpReport.Database.Tables(1).SetDataSource adoRS, 3
  CRViewer1.ReportSource = crpReport
  CRViewer1.ViewReport
End Sub

Private Sub Form_Load()
  Dim cnString As String
  sDocPath = App.Path & "\order1.rpt"
  sDBPath = App.Path & "\xtreme.mdb"
  cnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & sDBPath & ";" & _
             "Mode=Read|Write|Share Deny None;Persist Security Info=False;"
  adoCon.CursorLocation = adUseClient
  adoCon.Open cnString
  Set crpApp = New CRAXDRT.Application
End Sub


The TTX File

OrderID     Long          101
OrderDate     Date          08/06/2001
CustID     Long          2002
ProductID     Long          3003
UnitPrice     Currency          10.50
Quantity     Long          10
ProductIName     String     50     Sample Product Name

DRRYAN3
Avatar of rhubarbtwo

ASKER

Thanks DRRYAN3, my email is rhubarbtwo@yahoo.co.uk

At least if I can start with someone's working version I can see where I am going wrong. I wondered if it might be my cursor location, I wasn't using adoCon.CursorLocation = adUseClient and I know that gave me a problem with populating a data grid, but I checked that, still worth checking again though.
 
ASKER CERTIFIED SOLUTION
Avatar of DRRYAN3
DRRYAN3

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've pasted your code into a new project but changed the sDBPath, sDocPath, and SQL to point to my mdb, report, and table, but there's no change, so maybe the problem does lie in my report/mdb setup.
I'm ecstatic, you've solved it, knew it must be something simple! I found the 'save data with report' to be checked, once unchecked it works.

Cheers
I'll skip the email.  Glad you got it working.

DRRYAN3
Thanks
Any chance you can send me te same zip file you sent to rhubarbtwo on VB, Crystal 8 and passing a recordset?

If so jdillon@hermesofparis.com

Thanks

John