Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleBuild a hierarchical DataReport using a program-created Recordset
Keywordshierarchical DataReport, Recordset
CategoriesDatabase
 
Create the Recordset using New. Use a SHAPE APPEND statement in the Recordset's Open method to create the hierarchical Recordset.

Use AddNew to add new parent records. Then get the new record's child Recordset object and use its AddNew method to give it records.

Finally, set the report object's DataSource property to the parent Recordset and display the report.

Note: This program requires MDAC 2.5. Download it.

 
Private Sub cmdReport_Click()
Dim rs As ADODB.Recordset
Dim child_rs As ADODB.Recordset
Dim fld As ADODB.Field

    Set rs = New ADODB.Recordset
    rs.LockType = adLockBatchOptimistic
    rs.Open _
        "SHAPE APPEND " & _
        "  New adVarChar(10) As ParentDay," & _
        "  ((SHAPE APPEND" & _
        "    New adVarChar(10) As ChildDay," & _
        "    New adVarChar(10) As Name," & _
        "    New adInteger As Amount)" & _
        "  RELATE ParentDay to ChildDay) As Child", _
        "Provider=MSDataShape;Data Provider=None"

    rs.AddNew Array("ParentDay"), Array("Monday")
    rs.AddNew Array("ParentDay"), Array("Tuesday")

    Set child_rs = rs("Child").Value
    child_rs.AddNew Array("ChildDay", "Name", "Amount"), _
        Array("Monday", "Rod", -1.11)
    child_rs.AddNew Array("ChildDay", "Name", "Amount"), _
        Array("Tuesday", "Rod", 2.22)
    child_rs.AddNew Array("ChildDay", "Name", "Amount"), _
        Array("Monday", "Michelle", 11.11)
    child_rs.AddNew Array("ChildDay", "Name", "Amount"), _
        Array("Tuesday", "Cobe", -22.22)

    Set rptTest.DataSource = rs
    rptTest.Show vbModal

    rs.Close
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated