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?
rhubarbtwoAsked:
Who is Participating?
 
DRRYAN3Connect With a Mentor Commented:
I'll send the email in about an hour.  Check to see if you have the option on the file menu named Save Data with Report unchecked.  If it is checked, uncheck it and resave your report.  Look for email later today.

DRRYAN3
0
 
DRRYAN3Commented:
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
0
 
rhubarbtwoAuthor Commented:
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.
 
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
rhubarbtwoAuthor Commented:
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.
0
 
rhubarbtwoAuthor Commented:
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
0
 
DRRYAN3Commented:
I'll skip the email.  Glad you got it working.

DRRYAN3
0
 
rhubarbtwoAuthor Commented:
Thanks
0
 
JTD3Commented:
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
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.