|
Microsoft Office Application Development
|
|
Handling Worksheet control events using a class module. Creating the Class moduleFirst, insert a class module.
In the properties window, change its name from the default Class1 to clsObtHandler:
Now in the codepane, type these lines: Option Explicit After doing this, you will be able to select mobtOption from the lefthand dropdown list at the top of the codepane:
If you select this, the default Click event skeleton code is inserted in your module: Private Sub mobtOption_Click() If now you click on the right dropdown list, you will get all events available for this type of control through the class module:
Note, that the number of available events is less than when using the codemodule behind the worksheet:
Specifically, for this control the LostFocus event isn't available in a class module. other controls may have more events missing. Select the Change event from the dropdown and remove the click event. You should now have something like this: Option Explicit I said I wanted to change the color of the selected control and of course also change the de-selected one back. I also wanted a message about which option button has been selected. I devised this code for that: Private Sub mobtOption_Change() When one clicks one option button to select it, both the selected option button and the de-selected option button will fire their change events, so this Event sub will be run twice, once for the selected control and once for the de-selected control. The first will have a Value of 1 and the second a Value of 0.
| ||||||||||||||
|
Use the contact page to issue
questions or comments about this website. |