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
Solved

Passing an adoRS to an active report in CR8

Posted on 2001-08-07
8
395 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

828 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