Solved

Passing an adoRS to an active report in CR8

Posted on 2001-08-07
8
397 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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
 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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. …
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 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