grouping records in data report
how is group header/footer used?
i tried dragging the rpttextboxes (batch_no & batch_dte) from the details
to the group header.
but when i run the program, an error occurred.
the error is:
Report Sections do not match data source
so, i assigned a data source to my data report.
in my case, i used a recordset (which is Rst)
but it still has the same error...
how can i group my records?
your help is greatly appreciated... =)
Re: grouping records in data report
To use grouping on a DataReport its DataSource must be a hierarchical recordset, i.e. Parent-Child relationship (assuming unbound mode - I don't use DataEnvironment).
Try this sample.
VB Code:
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.
db.Open "provider=msdatashape;data provider=sqloledb;data source=handel;" _
& "initial catalog=northwind;integrated security=sspi"
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
Re: grouping records in data report
looks confusing... haven't tried this msdatashape thing... don't know if it'll work... but i'll try... thanks! =)