Access

Custom Cursors

Ease of Use

Intermediate

Version tested with

97 to 2007 

Submitted by:

bazarov

Description:

How to use Custom Cursors In MS Access. From a post on my Access blog: http://www.accessextra.net/ 

Discussion:

I create Access Switchboard products and was frustrated by the lack of native functionality in Access for using custom cursors, for example, using a hand cursor on non-hyperlink controls. Using VBA in Access, apart from the Hand cursor for a Hyperlink control and the Hourglass method of the DoCmd object, you can only use the MousePointer property of the Screen object to specify a mouse-pointer, with the cursor types limited to: * Default Arrow * Text Select (I-Beam) * Vertical Resize (Size N, S) * Horizontal Resize (Size E, W) * Busy (Hourglass) However, there are two API calls that allow you to use your own custom cursors or Windows system cursors in your Access applications. You can even use animated cursors. 

Code:

instructions for use

			

Option Compare Database Option Explicit ' Declarations for API Functions Private Declare Function LoadCursorFromFile Lib "user32" _ Alias "LoadCursorFromFileA" (ByVal lpFileName As String) As Long Private Declare Function SetClassLong Lib "user32" Alias_ "SetClassLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _ ByVal dwNewLong As Long) As Long Private Declare Function LoadCursor Lib "user32" Alias_ "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long ' Declare Windows API Constants for Windows System cursors Const GCW_HCURSOR = (-12) Const IDC_APPSTARTING As Long = 32650& Const IDC_ARROW As Long = 32512& Const IDC_HAND As Long = 32649 Const IDC_HELP As Long = 32651 Const IDC_IBEAM As Long = 32513& Const IDC_ICON As Long = 32641& Const IDC_WAIT As Long = 32514& Const IDC_UPARROW As Long = 32516& Const IDC_SIZEWE As Long = 32644& Const IDC_SIZENWSE As Long = 32642& Const IDC_SIZENS As Long = 32645& Const IDC_SIZENESW As Long = 32643& Const IDC_SIZEALL As Long = 32646& Const IDC_SIZE As Long = 32640& Const IDC_NO As Long = 32648& ' Declare handles for cursor Private Const GCL_HCURSOR = (-12) Private hOldCursor As Long Private hNewCursor As Long Private Sub Form_Load() 'Load cursor 'Comment out code not required: 'Load system cursor hNewCursor = LoadCursor(ByVal 0&, IDC_HAND) 'Load cursor from file hNewCursor = LoadCursorFromFile(CurrentProject.Path & "\cool.cur") 'Load animated cursor from file hNewCursor = LoadCursorFromFile(CurrentProject.Path & "\APPSTART.ani") hOldCursor = SetClassLong(Me.hwnd, GCL_HCURSOR, hNewCursor) End Sub Private Sub Form_Unload(Cancel As Integer) 'Unload cursor hOldCursor = SetClassLong(hwnd, GCL_HCURSOR, hOldCursor) End Sub

How to use:

  1. Place the code behind an empty Access form to see how the API calls work.
 

Test the code:

  1. Open the form in Form View and the On Load Event procedure will replace the default cursor with the custom cursor. Closing the form will fire the On Unload Event code which restores the default cursor.
 

Sample File:

curs_mdb.zip 16.52KB 

Approved by mdmackillop


This entry has been viewed 146 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express