Access – Controlling the Mouse Cursor

I recently saw that Mike Wolfe published an article about using APIs to control the mouse cursor in an application:

While I have use that exact approach myself in the past, I wanted to briefly touch upon a several other built-in solutions for controlling the mouse cursor that may avoid the need for the use of such APIs depending on your scenario.

Screen.MousePointer Property

The first possible solution to controlling the mouse cursor would be to use the Screen.MousePointer property.  For instance, you could use the Mouse Move event to trigger changing the cursor with a single line of code:

Screen.MousePointer = 1  'Standard Cursor
Screen.MousePointer = 3  'I Beam
Screen.MousePointer = 7  'Double Arrow Vertical
Screen.MousePointer = 9  'Double Arrow Horizontal
Screen.MousePointer = 11 'Hour Glass

Here’s what these number actually represent!

Access - MousePointer Property - CursorsThe Hour Glass cursor can vary in appearance and can be a Hour Glass or a Thinking animated cursor.

Notice an Important Omission?
Although very useful, this property does not allow us to use custom cursors, nor does it offer the ability to use other common built-in cursors such as the ‘hand’ like what you normally get when hovering over hyperlinks.

Also notice the holes in the property numbers, why did they not implement all the Form MousePointer properties when implementing this property also eludes me, but here we are, this is what we have to work with.

A Button’s ‘Cursor on Hover’ Property

Another interesting property which is available for button controls, is the ‘Cursor on Hover‘ property which enables you to select ‘Hyperlink hand’ so when the mouse is over top of a button you get a hand cursor instead of the default arrow (or whatever your default cursor is).

Limited to Buttons
Don’t ask me why, but this property only seems to be available with Button controls.  Why the development wouldn’t have made such a property universally accessible for all controls with all the cursors available eludes me as well.

Also note that I have found this property to be finicky and unreliable. Sometimes it works and other times it doesn’t!

DoCmd.HourGlass Method

If you’re looking to display the ‘Hour Glass’ cursor to show that the database is working, you can obviously use the Screen.MousePointer = 11, or another option would be to use the DoCmd.HourGlass method.

DoCmd.HourGlass True 'Display the Hour Glass cursor
DoCmd.HourGlass False 'Switch back to the Default cursor OR use: Screen.MousePointer = 1

This is great to use when automating process to show that there is something going on, even if it isn’t obvious to the user.

The nice thing with DoCmd.HourGlass is there are no numbers to remember, just simple True/False whether to display the Hour Glass, or not.

Note: You can also do this via Macros using the DisplayHourglassPointer action and setting the ‘Hourglass On‘ property to Yes/No. That said, if used in an embedded macro it will on remain as an hourglass for the duration of the execution of that embedded macro and then automatically resets itself. This is both a Pro and a Con depending on what you are trying to achieve!

Conclusion

Well, now you have multiple different approaches for controlling your mouse cursor in your Access database:

  • VBA – Screen.MousePointer Property (above)
  • Button Property – ‘Cursor on Hover’ property (above)
  • Macro/VBA – DoCmd.HourGlass (above, solely for Hour Glass)
  • VBA – Using APIs (explained in Mike’s article, link provided above)

No one approach is better than the other and it all comes down to your need.  Based on what you need to achieve you may pick any of the above, but as usual the KISS development principle is always advisable.

Other Resources on the Subject

 

4 responses on “Access – Controlling the Mouse Cursor

  1. Martin

    Hi Daniel, I’m an eat-sleep-breathe Access vba developer and have been for 20+ years (time flies). Firstly I’d like to thank you for your Access related articles, which have helped me out many times. Always well written, informative and helpful. Secondly, I’m hoping to pick your brain 🙂 I’ve replicated Excel-like mouse behaviour in an Access datasheet, so users can easily select & copy cells from any part of the datasheet into Excel. But having spend a couple of hours scouring the internet, I cannot find how to simply change the cursor to a ‘white plus sign’ (cell selection mode) mouse cursor. ie. The same cursor that appears by default in Excel, and when moving the mouse over the edges of a cell in an Access datasheet. Any ideas?

    1. Daniel Pineault Post author

      The only idea I would have would be to use the API approach to load the ico file. Now it’s a question of whether the file can be found in the Office folder or if you need to get one from the internet or make your own.