Share this Page URL
Help

Chapter 8. Adding Features and Function ... > Turning a Control On and Off - Pg. 297

Adding Features and Function to Forms With Me.lstCategories .Enabled = False .Value = Null End With End Select 297 5. 6. This event procedure contains a Select Case statement that uses the value of the option group ( grpViewExpensesBy.Value ) to set the Enabled property for each of the list boxes. For ex- ample, when Category is selected in the option group (the option group's value equals 1), the Enabled property for the Expense Categories list box is set to True and the Enabled property of the Campaigns list box is set to False. The Value property of the Campaigns list box is set to Null so that no item appears selected in the list box. If Campaign is selected in the option group (the value is 2), the code reverses the previous instructions so that the Campaigns list box is available and the Expense Categories list box is not. When Summary is selected (the option group has the value 3), neither list box is available and their value is set to Null. In this portion of the Select Case statement, we've used With ... End With constructions, which we described in Chapter 5, to set multiple properties for a control without having to repeat the control's name. Close the Visual Basic Editor, and then open the ExpenseViews form in Form view. Click Campaign in the View Expense By option group. As you can see here, the Expense Categories list box is no longer available. When you select Category in the option group, the Expense Categories list box is enabled, and you can't make any selection in the list of cam- paigns. A control's Visible property works similarly. In the ExpenseViews form, we could have set the Visible property for each list box to True or False depending on which item in the option group is selected.