onMouseOver equivalent for VBA (1 Viewer)

qwertyjjj

Registered User.
Local time
Today, 03:18
Joined
Aug 8, 2006
Messages
262
I'm trying to change a border from transparent to solid when a command button is moused over.
Is there an event to trigger this (similar to onMouseOver in JavaScript) ?
 

pdx_man

Just trying to help
Local time
Today, 03:18
Joined
Jan 23, 2001
Messages
1,347
I believe you are looking for OnMouseMove for the command button.
 

qwertyjjj

Registered User.
Local time
Today, 03:18
Joined
Aug 8, 2006
Messages
262
That works...thanks.
Is there an equivalent to onMouseOut as well?

So, when the mouse is moved over the command button it highlights a border but when it's moved off the command button, the border returns to its normal state?
 

pdx_man

Just trying to help
Local time
Today, 03:18
Joined
Jan 23, 2001
Messages
1,347
No, there isn't anything like that, but if you can use the Form's OnMouseMove to do what you want.
 

qwertyjjj

Registered User.
Local time
Today, 03:18
Joined
Aug 8, 2006
Messages
262
pdx_man said:
No, there isn't anything like that, but if you can use the Form's OnMouseMove to do what you want.

Do you have to add co-ordinates or something like that?
It works for when you forst mouse over the command button but it ust need to know when the mouse moves away from the button somehow ?
 

reach_dev

New member
Local time
Today, 11:18
Joined
Aug 17, 2006
Messages
9
qwertyjjj said:
Do you have to add co-ordinates or something like that?
It works for when you forst mouse over the command button but it ust need to know when the mouse moves away from the button somehow ?


I believe what was meant with the Form's onMouseMove is that it'll be triggered as the cursor travels off the command button onto the form, so you can put the code that would be in onMouseOut into the form's code for onMouseMove.
 

qwertyjjj

Registered User.
Local time
Today, 03:18
Joined
Aug 8, 2006
Messages
262
At the moment, it seems to be triggered when you move the mouse onto the button.

Either way, there must be a way of distinguishing between mobing on and moving off the button but not sure if there's an event for it or a standard way of doing this tye of stuff ??
 

reach_dev

New member
Local time
Today, 11:18
Joined
Aug 17, 2006
Messages
9
Just googled and found this;

Ive not tested it, and it looks more like VB5/6 than VBA but it might help you out.

Code:
Private Type POINT_TYPE
    X As Long
    Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32.dll" _
    (xyPoint As POINT_TYPE) As Long

Private Sub GetMyCursorPos()
    Dim cp As POINT_TYPE
    Dim rval As Long
    rval = GetCursorPos(curPos)' Get cursor location
    Label1.Caption = "The mouse is at X=" & curPos.X & " Y=" & curPos.Y
End Sub
 
R

Rich

Guest
Function fSetFontBold(stControlName As String)
Const cBold = 700
Const cNormal = 400

On Error Resume Next

With Me(mstPrevControl)
.FontWeight = cNormal
.ForeColor = 16777215
End With
mstPrevControl = stControlName
With Me(stControlName)
.FontWeight = cBold
.ForeColor = 65280
End With
End Function

Function fRemoveFontBold()
Const cNormal = 400
On Error Resume Next
With Me(mstPrevControl)
.FontWeight = cNormal
.ForeColor = 0
End With
End Function


OnMouseMove =fRemoveFontBold()
 

allan57

Allan
Local time
Today, 11:18
Joined
Nov 29, 2004
Messages
336
Attached is a Db with examples of buttons that I use in my databases.
 

Attachments

  • Example_Buttons.zip
    15.2 KB · Views: 1,435
Last edited:

pdx_man

Just trying to help
Local time
Today, 03:18
Joined
Jan 23, 2001
Messages
1,347
I would just have a global variable and set it to zero when the form opens.
On the buttons OnMouseMove event, set it to one.

On the forms OnMouseMove event, check this variable, if it equals one, then you know it was just on that button, set it to zero and do what you want to do.
 

Riverburn

Registered User.
Local time
Today, 03:18
Joined
Jul 7, 2010
Messages
31
reading the other posts, I wonder if what I did is exactly what you want, but it might help you or other people.

Code:
Private Sub addNotes_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
 
'MsgBox "X: " & X & " Y: " & Y
 
If X > 10 And X < 800 And Y > 10 And Y < 500 Then
    addNotes.BackColor = 240
End If
If X < 10 Or Y < 10 Or X > 800 Or Y > 500 Then
    addNotes.BackColor = 191
End If
End Sub

what this does basically is like onmouseover in Javascript.
when you add an MouseMove event to a something (label, box, textbox, combobox... anything) an even is trigered for every pixel you move (that are a lot of events). when the event is trigered data is given to the event: Button (what triggered the event), Shift (how many pixels were moved before the event was called again, the faster your cursor moves the higher this is), X (the coordinates IN the control where your mouse is horizontally), Y (same as X but vertically).

so basically what you do is check if X and Y are above 0 - which means the cursor entered from the left or top of the control, and under the width andlength, entering from the right or botom of the control.

when the cursor moves out of the bounds of the control, you change back to the original status. X and Y then have to be below zero (left from the top or left) or above the max length and width (left from the botom or right).

you can find your length and width by adding
Code:
MsgBox "X: " & X & " Y: " & Y
for me those values were 800 and 600 but it is highly likely those will differ for you.
hope this helps.
 

vbaInet

AWF VIP
Local time
Today, 11:18
Joined
Jan 22, 2010
Messages
26,374
This is a rather old thread (2006) but thanks for your contribution.

The only problem with this approach is if you mouse move very quickly then the event will not be fired. Which is why in Access most people tend to do a Mouse Move on the control to change the state and a Mouse Move on the section where the control is placed to revert it to its original state. You could use a variable (declared global within the scope of the form module) to check state like pdx man mentioned.
 

Riverburn

Registered User.
Local time
Today, 03:18
Joined
Jul 7, 2010
Messages
31
sorry about bumping an old thread :eek: got here through google.
probably it's best that I indeed use pbx's solution. another bad thing is that it kinda seems to keep my project real busy
 

vbaInet

AWF VIP
Local time
Today, 11:18
Joined
Jan 22, 2010
Messages
26,374
sorry about bumping an old thread :eek: got here through google.
probably it's best that I indeed use pbx's solution. another bad thing is that it kinda seems to keep my project real busy
Just create a boolean variable for example (global to the form module), and check against the boolean, then set the state if necessary. Instead of checking against the state of the control.
 

Users who are viewing this thread

Top Bottom