Visual Basic Concepts
Create a Data-Bound Report
You can create a data-bound report using the same drag-and-drop technique you used to create data-bound forms. Simply create a Command object based on a table or query, then drag it onto a blank report in the Data Report designer.
In this topic, you'll create a report that displays orders for French customers in the Northwind Traders sample database.
To create a data-bound report
Create a data environment Command object.
Open a Data Report designer.
Drag the Command object from the Data Environment designer to the Data Report designer.
Set data properties for the report.
Note This topic is part of a series that walks you through creating a simple database application that interacts with data in Nwind.mdb. It begins with the topic, Interacting with Data in a Microsoft Jet/Microsoft Access Database.
Create a Data Environment Command
You can follow the steps in the "Create a Data Environment Command Object" topic to create a command based on a table or in the "Create a Data Grid Form Based on a Query" to create a command based on a query. In this topic, you'll base the report on the FrenchCustomersOrders command you created in the "Create a Data Grid Form Based on a Query" topic.
Open a Data Report Designer
The Data Report designer lets you easily create reports from within the Visual Basic environment. You can use the Data Report designer to create a multiple-section data report, add controls to the report, and bind the report to data. You can also drag Command objects from the Data Environment designer to the Data Report designer.
To add a data report to your project, click Add Data Report on the Project menu. If the Data Report designer is not available on the Project menu, add it to your Visual Basic environment. Click Components on the Project menu, click the Designers tab, and then click the check box next to its name in the list of designers.
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.
For More Information See Writing Reports with the Microsoft Data Report Designer.
Drag the Command from the Data Environment to the Data Report
Dragging a data environment Command object onto a Data Report designer is similar to dragging it onto a form. When you drop the Command object onto the report's Detail section, the Data Report designer automatically creates controls to display data from the Command object's recordset and sets data properties that bind the controls to fields in the recordset.
For example, to create a report that displays the orders of French customers, select the FrenchCustomersOrders Command object you created in the "Create a Data Grid Form Based on a Query" topic. Then drag the Command object onto the detail section of a blank report.
Set Data Properties for the Report
When you drag a Command objectfrom the Data Environment, the Data Report designer automatically sets data properties for each control that it creates. However, before the report can display data, you must also set the report's DataSource and DataMember properties.
For example, to display the orders of French Customers, set the properties as follows:
Property | Setting |
DataMember | FrenchCustomersOrders |
DataSource | MyDataEnvironment |
When you run the report, the Data Report designer creates a report based on the records returned by the FrenchCustomersOrders Command object.
Step by Step
This topic concludes a series that walks you through creating a simple database application that interacts with data in Nwind.mdb. To start from the beginning, see Interacting with Data in a Microsoft Jet/Microsoft Access Database.