On Mouse Move

  • Thread starter Thread starter Gary Robinson
  • Start date Start date
G

Gary Robinson

Hi

When using the on mouse move event, is it possible ti return the name of the
object the mouse is over??

Many Thanks in advance

Gary
 
Each object has its own MouseMove event, so the object the mouse is over is
the object of which this is the MouseMove event, if you see what I mean?
There is no need to test, in the MouseMove event, what object the mouse is
over, because the very fact that this particular MouseMove event has been
fired tells you what object the mouse is over. For example ...

Private Sub Command0_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Me.Label3.Caption = "The mouse is over the 'Command0' object, or I would
not have been fired"
End Sub

Private Sub Detail_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Me.Label3.Caption = "The mouse is over the Detail object, or I would not
have been fired."
End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single,
Y As Single)
Me.Label3.Caption = "The mouse is over the form and not over any object
contained within the form, or I would not have been fired."
End Sub

Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Me.Label3.Caption = "The mouse is over the 'List1' object, or I would
not have been fired"
End Sub
 
Hi

I understand that, i probably should have explained myself better!! I have a
form with many buttons on it, in the past i have written a function that
turns the text colour of the button a certain colour when the mouse is over
it, which has worked well but meant that i had to a reference to the
function in each 'mouse move event' with the name of the object (so the
function knows which button to change the colour of) I was hoping there was
a way of having a generic function that could dtermine the name of the
button itself, so i would not have to type it out each time.

Thanks


Gary
 
I was hoping there was
a way of having a generic function that could dtermine the name of the
button itself, so i would not have to type it out each time.

Private Sub cmdOne_MouseEnter()
Call MouseEnter("cmdOne")
End Sub

Private Sub cmdTwo_MouseEnter()
Call MouseEnter("cmdTwo")
End Sub


' and this is the common subroutine
Private Sub MouseEnter(ControlName as String)
Me.Controls(ControlName).TextColor = rgbBlue
Me.lblStatusBar.Caption = "over the " & ControlName & " button"

End Sub


This is about as modular as it gets with VBA I'm afraid.

Hope it helps

Tim F
 
Tim Ferguson said:
Private Sub cmdOne_MouseEnter()
Call MouseEnter("cmdOne")
End Sub

Private Sub cmdTwo_MouseEnter()
Call MouseEnter("cmdTwo")
End Sub


' and this is the common subroutine
Private Sub MouseEnter(ControlName as String)
Me.Controls(ControlName).TextColor = rgbBlue
Me.lblStatusBar.Caption = "over the " & ControlName & " button"

End Sub


This is about as modular as it gets with VBA I'm afraid.

Well ...

If you change

Private Sub MouseEnter(ControlName As String)

to

Private Function MouseEnter(ControlName As String)

then you can set each individual control's OnMouseMove event *property*
to

=MouseEnter("TheControlName")
 
then you can set each individual control's OnMouseMove event *property*
to

=MouseEnter("TheControlName")

Of course!

Hang on: I always thought you couldn't put parameters into a Macro
properties. Must go experiment more...

All the best


Tim F
 
Tim Ferguson said:
Hang on: I always thought you couldn't put parameters into a Macro
properties. Must go experiment more...

Not sure what you mean by "Macro properties". I'm talking about the
event property that shows up on the Event tab of the control's property
sheet. And what you'd be doing wouldn't be calling a macro, it would be
evaluating a function expression. That has always worked for me,
parameters and all.
 
Back
Top