Change Mouse Pointer

P

prototype

Is it possible to change the mouse pointer to a hand when it is moved over a
particular control in a form? I'm using a bound text box and when the user
clicks on it another form opens up containing additional details. I would
like to change the mouse pointer to a hand when it is positioned over the
text box in order to remind the user of this functionality. Does anyone know
how to do this? Do I need to use a different control?

Thanks,
Chris
 
R

Rob Parker

Hi Chris,

Place the following directly in the On Mouse Move event for the textbox:
=mousecursor(32649)

HTH,

Rob
 
G

Graham R Seach

Chris,

I don't know of a way to display a Hand without having access to an icon or
cursor file.

You can check out the Screen.MousePointer property in Access Help, to see if
that will do what you want. Otherwise, the following may do it for you.

1. Get hold of a suitable icon file, and put it somewhere convenient.

2. Add the following to a standard module.

Private Declare Function LoadCursorBynum Lib "user32" _
Alias "LoadCursorA" ( _
ByVal hinstance As Long, _
ByVal lpCursorName As Long _
) As Long
Private Declare Function LoadCursorFromFile Lib _
"user32" Alias "LoadCursorFromFileA" ( _
ByVal lpFileName As String _
) As Long
Private Declare Function SetCursor Lib _
"user32" ( _
ByVal hCursor As Long _
) As Long

Public Enum CursorTypeEnum
csrSPPSTARTING = 32650& ' Standard arrow and small hourglass
csrARROW = 32512& ' Standard arrow
csrCROSS = 32515& ' Crosshair
csrIBEAM = 32513& ' Text I-beam
csrWAIT = 32514& ' Hourglass
csrUPARROW = 32516& ' Vertical arrow
csrSIZE = 32640& ' Windows NT only: Four-pointed arrow
csrICON = 32641& ' Windows NT only: Empty icon
csrSIZENWSE = 32642& ' Double-pointed arrow pointing northwest and
southeast
csrSIZENESW = 32643& ' Double-pointed arrow pointing northeast and
southwest
csrSIZEWE = 32644& ' Double-pointed arrow pointing west and east
csrSIZENS = 32645& ' Double-pointed arrow pointing north and south
csrSIZEALL = 32646& ' Same as IDC_SIZE
csrNO = 32648& ' Slashed circle
csrHELP = 32651& ' Arrow and question mark
End Enum

Public Function SetCustomCursor(Optional sCursorPath As String = "None",
Optional lCursorType As CursorTypeEnum = 0)
'Load a cursor using one of the cursor constants, or using a custom file
path
Dim lReturn As Long

If lCursorType > 0 Then
lReturn = LoadCursorBynum(0&, lCursorType)
ElseIf sCursorPath <> "" Then
lReturn = LoadCursorFromFile(sCursorPath)
Else
DoCmd.Beep
MsgBox "You must supply either an Enum value," & vbCrLf & "or a file
path.", _
vbOKOnly + vbExclamation, "Argument missing"
End If

lReturn = SetCursor(lReturn)
End Function


3. Then add the following line of code to the Textbox's MouseMove event:
Call SetCustomCursor("path to a suitable icon file")

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
J

Jeanette Cunningham

A different approach is to make the text box look like a hyperlink on a web
page.
Make the border of the text box invisible, set its backcolor to transparent
and change the text colour to the blue that we are familiar with for
hyperlinks.
If you wanted to you could display the text as underlined.

Jeanette Cunningham
 
D

Dirk Goldgar

prototype said:
Is it possible to change the mouse pointer to a hand when it is moved over
a
particular control in a form? I'm using a bound text box and when the user
clicks on it another form opens up containing additional details. I would
like to change the mouse pointer to a hand when it is positioned over the
text box in order to remind the user of this functionality. Does anyone
know
how to do this? Do I need to use a different control?


See this link:

http://www.mvps.org/access/api/api0044.htm
API: Displaying a custom Mouse icon

You don't need a special icon file, because the hyperlink-style "hand"
cursor is built-in. With the code from that link in a standard module, you
can set the text box's On Mouse Move property to:

=MouseCursor(32649)

.... without even needing to create an event procedure for the event.
 
G

Graham R Seach

Got that one now! Thanks Dirk.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
R

Rob Parker

Thanks Dirk,

My initial response was too rushed. I simply checked in my test.mdb, found
the event property entry on my sample "various actions" form, but forgot
about the underlying code module.

To the OP, "oops, sorry 'bout that"

Rob
 
V

Vic Rauch

This is GREAT! I've been looking for this for quite some time. For my ease of memory, I created a function named HandPointer() that I use in the On Mouse Move property. This way the MouseCursor(32649) is in the HandPointer() function and I don't have to remember the 32649 or look it up to use this idea.

Thank you Dirk!
Vic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top