The ADO Command object that the report is based on needs to be modified for grouping. Below is an example using Visual Basic 6.0's Data Environment and grouping in a report. Note that the command is doing the grouping, NOT the DataReport.
- Create a new Standard EXE project. Form1 is created by default.
- Add a reference to Microsoft ActiveX Data Objects 2.x Library.
- Add a DataEnvironment.
- Configure the Connection1 properties to use OLE DB Provider for SQL Server (SQLOLEDB) and the Northwind database (Nwind.mdb).
- Add a Command object off of Connection1.
- Configure the Command1 properties to use the Orders table and group by OrderDate (under the Grouping tab).
- Add a DataReport to your project.
- Set the DataSource to DataEnvironment1.
- Set the DataMember to Command1_Grouping.
- Right-click on DataReport1 and choose Retrieve Structure.
- From the Summary Fields in Command1_Grouping, click and drag the OrderDate field into the DataReport1 Group Header.
- Click and drag detail fields from the Detail Fields in Command1 into the DataReport1 Detail section.
- Add a CommandButton to Form1.
- Add the following code to Form1:
Private Sub Command1_Click()
DataReport1.Show 1
Unload DataReport1
End Sub
- Run the project and click Command1.
It is important that the report sections match the command object's structure. If the error continues to occur, try using the Retrieve Structure command on the DataReport to refresh the sections. Retrieve Structure will remove all fields that are currently in the DataReport.