Binding a Control to a Data Control
A data control opens a database To see this data in controls on your form, you must bind those controls to the data control. A control is bound to a specific field in the Dynaset represented by the Recordset property of a data control. Controls can be bound to the data control with the DataSource property only at design time, but can be bound to a field at run time with the DataField property. You can bind the check box, image, label, picture, and text box controls. and creates a Dynaset object containing data from the database.
To bind a text box to a data control at design time
1. On your form, select a control you want to bind to a data control.
2. In the Properties window, select the DataSource property and click the (...) button next to the Settings list box to see a list of the data controls on the form. Select the data control you want.
3. Select the DataField property, and click the (...) button next to the Settings list box to see a list of the available fields in the Recordset property of the data control. (If you haven't yet set the RecordSource property of the data control, this list will be empty.) Select the field you want.
To bind a text box to a data control in code
1. You must set the DataSource property of the text box to the name of the data control (for example, "Data1") at design time.
2. Set the DatabaseName and RecordSource properties of the data control.
Data1.DatabaseName = "C:\VB\BIBLIO.MDB" ' Set the database.
Data1.RecordSource = "Publishers" ' Set the table or query.
3. Set the text box's DataField property to the name of the field in the control's Recordset property.
Text1.DataField = "State" ' Bind to State field.