Create a simple DataCombo application
The following example uses the DataCombo control to create a data entry interface for the titles table of the Northwind.mdb sample database. This input interface enables users to enter new products and assigns them to existing vendors by providing a lookup table that includes all vendor names. When users enter the value of a vendor field in the input form, they can select a vendor from a list box. When they select a vendor, the vendor's SupplierID field value is copied to the SupplierID field in the Products table.
To use the DataCombo control to create a lookup table
1. Create an OLE DB data source for the Northwind database. If you have not yet created a data source, follow the steps in "Creating an OLE DB data source for Northwind."
2. Create a new standard EXE project in Visual Basic. If the DataGrid, DataCombo, or ADO Data control is not in the Toolbox, right-click the Toolbox, and then use the Parts dialog box to add the control.
3. Add a DataCombo control, two ADO data controls, and a DataGrid control to the form. 4. In the Properties window, set the properties of the first Data Control (ADODC1) as shown in the following table.
4. In the Properties window, set the properties of the first Data Control (ADODC1) as shown in the following table.
5. In the Properties window, set the properties of the second Data Control (ADODC2) as shown in the following table.
6. In the Properties window, set the properties of the DataGrid control as shown in the following table.
7. In the Properties window, set the properties of the DataCombo control as shown in the following table.
8. Finally, add the following code to the form's code module:
Private Sub Form_Load ()
' Hides the SupplierID field in the DataGrid control so that the user
' doesn't confuse which value to change.
Grdproducts.columns ("SupplierID"). Visible = False
End Sub
9. Run the project.
You can browse through the recordset by clicking the arrows on the visual ADO Data control. If you do this, the DataCombo control updates and displays the name of the vendor for each product. If you want to edit the SupplierID field, click the arrow for the DataCombo control to display a Drop-down list, and then click a different vendor to change the value written to the SupplierID field.