Results 1 to 3 of 3

Thread: grouping records in data report

  1. #1

    Thread Starter
    Addicted Member jeanette_db's Avatar
    Join Date
    Oct 2005
    Location
    DC, Phil
    Posts
    215

    Unhappy 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... =)
    Last edited by jeanette_db; Oct 20th, 2005 at 12:42 AM.

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    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:
    1. Dim db As ADODB.Connection
    2. Dim rs As ADODB.Recordset
    3. Dim dteFormat As StdDataFormat
    4. Dim strSQL As String
    5.  
    6. Set db = New ADODB.Connection
    7.  
    8. 'A hierarchical recordset requires the MSDataShape provider.
    9. db.Open "provider=msdatashape;data provider=sqloledb;data source=handel;" _
    10.       & "initial catalog=northwind;integrated security=sspi"
    11.  
    12. Set rs = New ADODB.Recordset
    13.  
    14. strSQL = "Shape {Select CustomerId, CompanyName From Customers} " _
    15.     & "Append ({Select CustomerId, OrderId, OrderDate From Orders} As Orders " _
    16.     & "Relate CustomerId To CustomerId)"
    17.  
    18. rs.Open strSQL, db, adOpenStatic, adLockReadOnly
    19. Set rs.ActiveConnection = Nothing
    20.  
    21. 'Group header section - contains 1 unbound rptTextBox control
    22. DataReport1.Sections("Section6").Controls(1).DataField = "CompanyName"
    23.  
    24. 'details section - contains 2 unbound rptTextBox control
    25. With DataReport1.Sections("Section1").Controls
    26.     .Item(1).DataMember = "Orders" 'indicate the field is from the Child recordset
    27.     .Item(1).DataField = "OrderId"
    28.    
    29.     Set dteFormat = New StdDataFormat
    30.     dteFormat.Type = fmtCustom
    31.     dteFormat.Format = "dd-MMM-yyyy"
    32.  
    33.     .Item(2).DataMember = "Orders"
    34.     .Item(2).DataField = "OrderDate"
    35.     Set .Item(2).DataFormat = dteFormat
    36. End With
    37.  
    38. 'Group Footer section - contains 1 unbound rptFunction control
    39. 'indicates the total # of orders per customer group
    40. With DataReport1.Sections("Section7").Controls
    41.     .Item(1).DataMember = "Orders"
    42.     .Item(1).DataField = "OrderId"
    43.     .Item(1).FunctionType = rptFuncRCnt
    44. End With
    45.  
    46. DataReport1.Sections("Section7").ForcePageBreak = rptPageBreakAfter
    47.  
    48. Set DataReport1.DataSource = rs
    49. DataReport1.Show
    50.  
    51. Set dteFormat = Nothing
    52. Set rs = Nothing
    53. db.Close
    54. Set db = Nothing

  3. #3

    Thread Starter
    Addicted Member jeanette_db's Avatar
    Join Date
    Oct 2005
    Location
    DC, Phil
    Posts
    215

    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! =)
    Last edited by jeanette_db; Oct 26th, 2005 at 08:59 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width