This topic creates a simple data report using a Data Environment designer as a data source. The Data Environment designer uses the NorthWind database supplied with Visual Basic to create a simple hierarchical cursor. The cursor contains two tables, Customers and Orders, and uses the CustomerID field to link the two. The finished report resembles the figure below.
Simple Data Report: Order Dates by Customers
Before you begin the step-by-step process, ensure that the Northwind database (Nwind.mdb) is present on your computer. If it is not present, copy the file from your Visual Basic CD onto your hard disk.
To create a simple hierarchical cursor in the Data Environment designer
Note The first four kinds of ActiveX designers loaded for a project are listed on the Project menu. If more than four designers are loaded, the later ones will be available from the More ActiveX Designers submenu on the Project menu.
Property | Setting |
Command Name | Customers |
Connection | Northwind |
DataBase Object | Table |
Object Name | Customers |
Property | Setting |
Command Name | Orders |
Connection | Northwind |
DataBase Object | Table |
Object Name | Orders |
When designing relational databases, it's customary for related tables to use the same name for linking fields. In this case, the linking fields are both named CustomerID. The Data Environment designer automatically matches such pairs in the dialog box.
Clicking the Add button adds the relation to the Command object. After closing the dialog box, the Data Environment designer reflects the relationship by displaying the two commands as a hierarchy. This hierarchy will be used to create the data report.
Object | Property | Setting |
Project | Name | prjNwind |
DataEnvironment | Name | deNwind |
Form | Name | frmShowReport |
Once the Data Environment designer has been created, you can create a data report. Because not all of the fields in the data environment will be useful in a report, this series of topics creates a limited report that displays only a few fields.
To create a new data report
Note The first four kinds of ActiveX designers loaded for a project are listed on the Project menu. If more than four designers are loaded, the later ones will be available from the More ActiveX Designers submenu on the Project menu.
Property | Setting |
Name | rptNwind |
Caption | Northwind Data Report |
Important To set the DataSource property to deNwind, the Data Environment designer must be open. If it is closed, press CTRL+R to display the Project window, then double-click the data environment icon.
You have added a new group section to the designer. Each group section has a one-to-one correspondence to a Command object in the data environment; in this case, the new Group section corresponds to the Customers Command object. Notice also that the Group Header has a matching Group Footer section.
Note The Data Environment allows you to create hierarchies of Command objects wherein a Command object has more than one child object — child Command objects parallel to each other. The Data Report designer, however, is not as flexible, and can't display more than one child object at a time. In such cases, when executing a Retrieve Structure command, the Data Report will display only the first of the child commands, and none below it. Thus you should avoid creating Command hierarchies with parallel children commands.
The Group Header section can contain any field from the Customers command, however, for demonstration purposes, only the Customer name is displayed at this time.
If you do not want a Label control to be included with the TextBox control, you can uncheck the Drag and Drop Fields Caption option on the Field Mapping tab of the Data Environment designer's Options dialog box.
The Details section represents the innermost "repeating" section, and thus corresponds to the lowest Command object in the Data Environment hierarchy: the Orders Command object.
It's important to resize the height of the Details section to be as short as possible because the height will be multiplied for every OrderDate returned for the CompanyName. Any extra space below or above the OrderDate text box will result in unneeded space in the final report.
Now that the data environment and the data report objects have been created, you are almost ready to run the project. One step remains: to write code to show the data report.
To show the data report at run time
When you add a Data Report designer to your project, its controls are added to the tab named DataReport. To use the standard Visual Basic controls, you must switch to the General tab.
Property | Setting |
Name | cmdShow |
Caption | Show Report |
Private Sub cmdShow_Click()
rptNwind.Show
End Sub
You can also display the data report with no code at all.
Note If you use this method, you can remove the Form object from your project.
This topic is part of a series that walks you through creating a sample data report.
To | See |
Go to the next step | Extending the Data Report |