Solved

Passing an adoRS to an active report in CR8

Posted on 2001-08-07
8
390 Views
Last Modified: 2012-08-13
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?
0
Comment
Question by:rhubarbtwo
  • 4
  • 3
8 Comments
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6360145
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
 

Author Comment

by:rhubarbtwo
ID: 6363025
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
 
LVL 12

Accepted Solution

by:
DRRYAN3 earned 200 total points
ID: 6364148
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
 

Author Comment

by:rhubarbtwo
ID: 6364159
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:rhubarbtwo
ID: 6364196
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
 
LVL 12

Expert Comment

by:DRRYAN3
ID: 6364351
I'll skip the email.  Glad you got it working.

DRRYAN3
0
 

Author Comment

by:rhubarbtwo
ID: 6364752
Thanks
0
 

Expert Comment

by:JTD3
ID: 7029557
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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now