Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Populating dynamically loaded .rpt with ADO recordset.

Status
Not open for further replies.

climberhunt

Programmer
Sep 13, 2000
3
IE

I'm trying to populate a report with an ADO recordset.
The following code is what I have so far.
Code:
Dim oApp As New CRAXDRT.Application
Dim oRpt As CRAXDRT.Report
Dim rsResults As New ADODB.Recordset

    Set oRpt = oApp.OpenReport("c:\MyReport.rpt")
    PopulateRS rsResults
    ' rsResults now contains data.
    oRpt.Database.SetDataSource rsResults
    oRpt.ReadRecords
    CRViewer1.ReportSource = oRpt
    CRViewer1.ViewReport
That code will only show the sample rows that were saved
with the .rpt when it was created, not the rows from the
recordset at runtime. All the columns in the recordset match
exactly the report definition, because the same stored
procedure (in Sybase) was used to create the report at
design time and to populate the recordset at runtime.

Cheers,
Dave.
[sig][/sig]
 
Try changing the source via the RPT and not the viewer
Consider the following code:
Code:
Dim oApp As New CRAXDRT.Application
Dim oRpt As CRAXDRT.Report
Dim rsResults As New ADODB.Recordset

    ' Fetch the report
    Set oRpt = oApp.OpenReport("c:\MyReport.rpt")
    PopulateRS rsResults

    ' Change the data
    oRpt.DiscardSavedData
    oRpt.Database.Tables(1).SetPrivateData 3, rsResults 
    oRpt.ReadRecords

    'View the report
    CRViewer1.ReportSource = oRpt
    CRViewer1.ViewReport
If that does not do the trick, what happends when you add the
Code:
oRpt.DiscardSavedData
line of code to what you have now? [sig]<p>Steven Fowler<br><a href=mailto:info@fowlerconsulting.com>info@fowlerconsulting.com</a><br><a href= Consulting</a><br>[/sig]
 
Dave,

Or, you could simply not save the RPT with data, something you don't want to do for reports that will be run from a program.

I am not sure why Seagate insists on setting that as the default for new reports. It is the first thing that I shut off on a new install of Crystal (along with smart linking and the unexplainable &quot;allow field clipping&quot; for numbers.) Some users never realize that these options can be shut off.

Ken [sig]<p>Ken Hamady<br><a href=mailto:ken@kenhamady.com>ken@kenhamady.com</a><br><a href= Reports Taining by Ken Hamady</a><br>[/sig]
 
Stephen, the oRpt.DiscardSavedData method causes the parameter entry dialog to pop up. I had tried this before to no avail.
Ken, the oRpt.DiscardSavedData achieves the same thing, I had intended to save the report without data when I got
all this working.
I have since found out the following, having researched further.

The method I want to use is oRpt.AutoSetUnboundFieldSource.
This allows columns in a recordset to automatically bind to unbound fields on a report. The only problem is, that unbound fields can only be created on a form using the designer within VB. The stand-alone Crystal Reports
designer doesn't allow this. I had intended that our customers could create reports, drop them into a particular directory as &quot;plug-ins&quot;, so that my application would display and print them, having bound them to recordsets. I now have this working with reports created within the IDE and saved as .rpt files, but that's no good. Means that the customer has to have VB and CR installed to create reports with unbound fields.
That's the key, the ability to create unbound fields on the report at design time.
Until Seagate release a version of the stand-alone designer with the ability to create unbound fields, it's useless to me for that purpose.

Seagate are probably thinking that it makes no sense to want to create unbound fields on a standalone report. This is probably the only situation where it would make sense.

Cheers,
Dave.


[sig][/sig]
 
Problem Solved! :)

If you use the Active Data Driver (using the relevant flavour, ADO for the following example) to develop the report, and save it as a .rpt file (with or without the data), you can then use the following code to populate a recordset and point the report at it. you can then use the CRviewer to view the report.
Code:
Dim oApp As New CRAXDRT.Application
Dim rsResults As New ADODB.Recordset
Dim oRpt As CRAXDRT.Report

Set oRpt = oApp.OpenReport (&quot;c:\reports\FindADO.rpt&quot;)
PopulateRS rsResults
oRpt.Database.SetDataSource rsResults
                   
CRViewer1.ReportSource = oRpt
CRViewer1.ViewReport

The rsResults columns must match the column definitions that were created at the design time of the report.

This also means that non-VB people can use the stand-alone Crystal Designer to develop reports, to be later incorporated dynamically into your VB application.

Just what I wanted!

Cheers,
Dave.
[sig][/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top