Me.Combo0.SetFocus
End Sub
This code assumes that the two drop-down boxes you created are called Combo0 and
combo2, and the text box is called Text4. These are the default names given as the controls
are created.
This code is called when the SupplierSize drop-down is changed. The value of the
SupplierSize drop-down is captured into a string variable and then the row source for
the SupplierName drop-down is altered according to the SupplierSize chosen. Also, if
the SupplierSize is “Small”, then the SupplierRef text box is not visible.
In the code window, select Form in the drop-down at the top-left corner and choose the
Current event in the drop-down in the top-right corner of the window.
Enter the following code:
Private Sub Form_Current()
Combo0_Change
End Sub
This ensures that as the user browses through the records in tblSupplier, the form is updated
according to what SupplierSize is showing.
Save the form and then load it in Form view.
As you move through the records, you will see that the controls on the form automatically
change to suit the SupplierSize field. If you click the SupplierName drop-down, you will see
this is populated according to what the SupplierSize control is showing.
If you change the SupplierSize field, then the drop-down for SupplierName will also
automatically change.
Chapter 39: Make Controls on Forms Interactive 353