Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Dim dteFormat As StdDataFormat
Dim strSQL As String
Set db = New ADODB.Connection
'A hierarchical recordset requires the MSDataShape provider.
[B]db.Open "provider=msdatashape;data provider=sqloledb;data source=handel;" _
& "initial catalog=northwind;integrated security=sspi"[/B]
Set rs = New ADODB.Recordset
strSQL = "Shape {Select CustomerId, CompanyName From Customers} " _
& "Append ({Select CustomerId, OrderId, OrderDate From Orders} As Orders " _
& "Relate CustomerId To CustomerId)"
rs.Open strSQL, db, adOpenStatic, adLockReadOnly
Set rs.ActiveConnection = Nothing
'Group header section - contains 1 unbound rptTextBox control
DataReport1.Sections("Section6").Controls(1).DataField = "CompanyName"
'details section - contains 2 unbound rptTextBox control
With DataReport1.Sections("Section1").Controls
.Item(1).DataMember = "Orders" 'indicate the field is from the Child recordset
.Item(1).DataField = "OrderId"
Set dteFormat = New StdDataFormat
dteFormat.Type = fmtCustom
dteFormat.Format = "dd-MMM-yyyy"
.Item(2).DataMember = "Orders"
.Item(2).DataField = "OrderDate"
Set .Item(2).DataFormat = dteFormat
End With
'Group Footer section - contains 1 unbound rptFunction control
'indicates the total # of orders per customer group
With DataReport1.Sections("Section7").Controls
.Item(1).DataMember = "Orders"
.Item(1).DataField = "OrderId"
.Item(1).FunctionType = rptFuncRCnt
End With
DataReport1.Sections("Section7").ForcePageBreak = rptPageBreakAfter
Set DataReport1.DataSource = rs
DataReport1.Show
Set dteFormat = Nothing
Set rs = Nothing
db.Close
Set db = Nothing