Microsoft Office 2000 Developer |
Once a data source has been created, it's a simple task to display or otherwise manipulate the data. There are several ways to display data:
Data-aware controls are distinguished by the presence of the DataSource property. For data-aware controls such as the Hierarchical FlexGrid and the DataGrid, simply set the control's DataSource property to the name of the data source, as shown here:
' Bind a DataGrid control to an ADO Data Control named ADODC1.
Set DataGrid1.DataSource = ADODC1
For Access
Set DataGrid1.DataSource = ADODC1.Object
This code can be placed in an automatically occurring event such as the Worksheet object's Activate event or in a triggered event such as the CommandButton's Click event.
For more information about using the controls, see Using Data-Aware Controls in Office Applications.
Not all controls are data-aware, that is, not every control has a DataSource property. To bind data to non data-aware controls (for example, the Access TextBox control), use the BindingCollection object.
The Microsoft Data Binding Collection manages the interaction between data consumers and data sources. In VBA 6.0, the Data Binding Collection is a creatable object that facilitates binding between both visual and non-visual objects.
To use data binding, you only have to set properties to tell the data source control where the data is coming from (for example, an Oracle server) and which other component (referred to as the data consumer) is to display and/or update the data. Then, VBA automatically handles moving the data back and forth from the data source to the data consumer as well as updating the data when necessary.
For more explanation and an example of using the BindingCollection object, see Binding any Control to a Data Source Using the BindingCollection Object.
The Data Report designer is a new, integrated report writer that makes it easy for you to create sophisticated printed reports from live data and provides programmatic control at run time.
The Data Report designer is fully integrated with the Data Environment designer. You can use a drag-and-drop operation to move individual data fields or entire recordsets from the Data Environment to easily create new reports. For a greater level of control, you can use code to manage formatting, printing, previewing, calculating, and saving of your hierarchical reports.
For detailed information on creating data reports, see "Writing Reports with the Microsoft Data Report Designer" in the Visual Basic documentation.
You can also display data by exploiting the object model of an application. For example, you can directly import data into an Excel worksheet by setting the Value property of the Range object to selected data.
In Office 2000 Developer, an Application object is a publicly creatable object. For example, the following code creates an instance of (also known as instantiating or referencing) the Excel application object and then uses the reference to access a public Excel function.
Excel.Application.Workbook.Add ' Add a new workbook to the application instance.
Office 2000 Developer includes complete object model documentation for all applications. For an example, see Displaying Data from a Recordset in an Excel Worksheet.