Using the Accessibility Class
As with any other class module, you'll need to create a new instance of the Accessibility class before you can use its properties. To do so, you create a variable that will refer to the new instance and work with that variable directly, like this:
Dim oAccess As Accessibility ' and then, later in your code: Set oAccess = New Accessibility ' or just use: ' Dim oAccess As New Accessibility ' if you don't care when the object gets created.
Once you've created the object, use it as you would any other object, setting and retrieving its properties. For example, the following fragment enables the StickyKeys functionality, enables the hot key, and turns on the sound effect when users use the feature:
Dim oAccess As New Accessibility With oAccess ' No point working with this feature if it's not ' available on this computer. If .skAvailable Then .skActive = True .skHotKeyActive = True .skAudibleFeedback = True End If End With
Some of the Accessibility class properties are interrelated, so read the descriptions carefully. For example, you cannot set both the fkBounceMSec and fkDelayMSec properties to nonzero values. If you try to set them both, Windows disregards your changes.
If you receive error 91, “Object variable or With block variable not set,” it's almost guaranteed that you've declared an object variable but haven't instantiated it yet. You must use the New keyword to create an object; otherwise, you're just creating a variable that can refer to the object. Make sure you either use New when you declare the object or use the Set keyword to point the variable you created to a new instance of the object. (See Chapter 5 for more information on creating and using object variables.)