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!

Problem passing ADO recordset to subreport

Status
Not open for further replies.

jbradley

Programmer
Sep 7, 2001
248
US
I built a small report viewer in VB6 using the ActiveX CrystalReport1 control. I have a report that pulls its data from an ADO recordset. I added a subreport that I want to have use the same record source but when the report is displayed the subreport contains no data.

What do I need to add to pass the recordset to the subreport? Here's my code:

cn.Open strConnect
rs.Open "SELECT * FROM DataInput WHERE Date='" & Format(DTPicker1, "mm/dd/yy") & _
"' AND CostCenter='" & strCostCenter & "'", cn, adOpenKeyset, adLockReadOnly
With CrystalReport1
.WindowTitle = "Metrics Tick Sheet Report"
.ReportFileName = App.Path & "\Daily Volume and Time Report.rpt"
.SetTablePrivateData 0, 3, rs
.Destination = crptToWindow
.Action = 1
End With
rs.Close: Set rs = Nothing
cn.Close: Set cn = Nothing

Thanks in advance for any help...
 
I'm not sure you can open up the subreport and pass an ADO recordset to the subreport with the OCX.

You can definitely do it with the RDC objects or the Automation Server objects (preferably the RDC).
 
For now I ended up saving the subreport as a stand-alone report and adding a new command button to my viewer to display it.

For future projects like this I'll probably go right for the RDC. The added flexibility is a real plus when a simple project suddenly gets complicated. :)
 
jbradley,

This is not a solution to your original problem, but a question from a novice developer.

My understanding is that your report retrieves data from a ADO recordset at runtime.

How did you create the report at design time (since the recordset does not exist at that stage) i.e. how did you define the fields in your report ?

Pointing me in the right direction on this issue would be most appreciated.

p.s. Currently I am using CR ver 4 (the one that comes with VB6, purchasing CR 8.5 in near future)

Regards,

Moben.
 
Moben,

You need to create a Field Definition File. This is just a tab-delimited text file laid out like this:

FieldName FieldType (String, Currency, Number, Date, etc.) FieldSize (for String fields) SampleData (optional)

It should include all the fields returned by your query or contained in the table it represents. Valid types are Blob, Boolean, Byte, Currency, Date, Long, Memo, Number, Short and String. The list has to be in exactly the same order as in the query or table. You can create the file in Notepad or there may be a Data Definition Tool available. I know it is with 8.5, I don't know about the version included with VB. Save your file with the extension .ttx.

Start designing your report. For your database, first select More Data Sources, then Active Data, then Active Data (Field Definitions Only). A Select Data Source dialog should open. If one of your choices is New then you can use the tool to build the file, otherwise you'll have to do it by hand. If you've done it by hand, then browse to the definition file or enter the full path and name in the text box provided. Once that's done you should have all of your fields available for the report. If any are missing, check your definition file for errors or omissions. Common mistakes (for me) are leaving a field out altogether, using a space instead of a tab, and leaving out the length specifivation for a string field.

Hope this helps . . .

Brad
 
Brad,

Thanks for your quick response to my questions. I've created a table layout as you described and saved it with the ttx extension.

I'm not sure how I can use this file within CR as you have described, or its possible that this cannot be done in CR 4.

I get an invalid database type error when attempting to use my data definition (cust.ttx) file.

Thanks once again.

Moben.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top