Microsoft Office 2000 Developer |
To bind a data source to a non data-aware control that does not have a DataSource property, you need to use the Microsoft Data Binding Collection. The Data Binding Collection permits any control to be bound to the Data Environment, the ADO Data Control, or ADO Recordset objects.
The BindingCollection object is a collection that has a DataSource property. After setting the DataSource property to a data source, you add Binding objects to the collection. Each Binding object binds a field from the data source to an appropriate property of any control. For example, to bind an Access TextBox control to a data source, the following code could be used:
BmCustomers.Add TextBox1, "Text", "CompanyName"
To use the BindingCollection object
Option Explicit
Private bmCustomers As New BindingCollection
' Assuming an ADO Data Control configured to connect to the Customers
' table. The TextBox is named Text1; the code binds the CompanyName
' field to the Text property.
Private Sub UserForm_Initialize()
Set bmCustomers.DataSource = ADODC1
BmCustomers.Add TextBox1, "Text", "CompanyName"
End Sub
For More Information For an example of binding controls using the BindingCollection object, see Adding Multiple Data Sources to an Access Form. For more information about the Data Binding Collection, see "Binding a Control to a Data Source" in the Visual Basic Programmer's Guide.