UseHand(): Changing the Mouse Cursor in Microsoft Access

A classic Microsoft Access mouse cursor trick gets simplified and updated for 64-bit VBA compatibility.

UseHand(): Changing the Mouse Cursor in Microsoft Access

Years ago, I came across an article from Mister Slimm, Microsoft Access 2002 – Emulate hyperlink cursor change.

The article shows how to use a couple of API calls to force the mouse to use the Windows hyperlink hand icon when moving over any control or form section in Microsoft Access.  As with many articles of that era, the API calls are 32-bit only.  There is also a bunch of extra fluff (four-way arrow mouse cursor, anyone?) that I've never felt the need to use over the past 15 years.

I've stripped the extra stuff out, added some code for 64-bit compatibility, and performed some light refactoring to minimize the amount of code you need to copy.

The Code

Here is my adaptation of Mister Slimm's original code:

' UseHand() declarations - paste the #If - #End If lines at the top of the module
#If VBA7 Then
    Private Declare PtrSafe Function LoadCursor Lib "user32" Alias "LoadCursorA" ( _
                                    ByVal hInstance As LongPtr, _
                                    ByVal lpCursorName As Long) As LongPtr
    Private Declare PtrSafe Function SetCursor Lib "user32" (ByVal hCursor As LongPtr) As LongPtr
#Else
    Private Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" ( _
                                    ByVal hInstance As Long, _
                                    ByVal pCursorName As Long) As Long
    Private Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
#End If

'---------------------------------------------------------------------------------------
' Purpose   : Use instead of hyperlink to change mouse cursor to pointing hand.
' Author    : "Mister Slimm"
' Source    : http://misterslimm.wordpress.com/2007/06/21/microsoft-access-2002-emulate-hyperlink-cursor-change/
' Adapted By: Mike Wolfe 
' Reposted  : https://nolongerset.com/usehand/
' Usage     : Set OnMouseMove of control to =UseHand()
'---------------------------------------------------------------------------------------
Public Function UseHand()
    Const IDC_HAND As Long = 32649&
    
    ' Load new cursor and, if successful, set it
    Dim hLastCursor As Variant  'Long/LongPtr
    hLastCursor = LoadCursor(0, CLng(IDC_HAND))
    If (hLastCursor > 0) Then
        hLastCursor = SetCursor(hLastCursor)
    End If
End Function

Usage

Enter =UseHand() in the On Mouse Move event of the control where you want the cursor to switch to a hyperlink hand:

If for some reason you would like to use one of the other built-in cursors, you can use one of the values in the lpCursorName table of the LoadCursorA documentation.

External references

Microsoft Access 2002 – Emulate hyperlink cursor change

LoadCursorA function (winuser.h) - Win32 apps
Loads the specified cursor resource from the executable (.EXE) file associated with an application instance. (ANSI)

All original code samples by Mike Wolfe are licensed under CC BY 4.0