Form on mouse move event? (1 Viewer)

hfl

Registered User.
Local time
Today, 05:18
Joined
Sep 17, 2015
Messages
31
Hello :)

Yesterday I moved from Access 2007 to 2013 because all other computers here at work is updating Office so now I have a small problem with a few of my forms.

In 2007 I used "form on mouse move event" so I didn't have to use an click event on all buttons on the form, this way I would just name the button "btnIDXXX" where XXX is the ID of the record and I could left click on the buttons to open them in a new form, just hovering over the buttons would do nothing.

My function code below.

Code:
Public Sub MouseUI(Frm As Form)

Dim btnID As String

        If Left(Frm.ActiveControl.Name, 5) = "btnID" Then
  
            btnID = Right(Frm.ActiveControl.Name, Len(Frm.ActiveControl.Name) - 5)
            
            Frm.btn_List.SetFocus
            
            DoCmd.OpenForm "InstrumentInfo", , , _
            "[InstrumentList.ID]= " & btnID
                                      
        Else
        
            If Left(Frm.ActiveControl.Name, 8) = "btnClose" Then
        
            DoCmd.Close acForm, Frm.Name
                    
            End If
        
        End If

End Sub

Then on the "form on mouse move event" I would just have

Code:
Call MouseUI(me)

And this worked perfect in 2007 but now that I am on 2013 for some reason it looks like the form on mouse move event don't register at all. the closest I am to a solution is moving the "Call MouseUI(me)" code to form on mouse wheel event but then I have to click the button to set focus then scroll with the mouse wheel to open the record in a new form...

I have tried to google this but couldn't find any change in form mouse events from Microsoft or anyone else with this exact problem so any help would be appreciated :)

Edit-------- <Static> fixed my problem and here is the code I used :)

Code:
Public Sub TestUI_Load(frm As Form)

Dim Name As String
Dim ctl As Control
                 
        For Each ctl In frm.Controls
        If Left(ctl.Name, 5) = "btnID" Then
            ctl.OnClick = "=OnMouseClickEvent(""" & Mid(ctl.Name, 6) & """)"
        End If
    
    Next

End Sub

Public Function OnMouseClickEvent(btnID As String)
    DoCmd.OpenForm "InstrumentInfo", , , "[InstrumentList.ID]= " & btnID
End Function

Code:
Private Sub Form_Open(Cancel As Integer)
    
    Call TestUI_Load(Me)

End Sub
 
Last edited:

missinglinq

AWF VIP
Local time
Yesterday, 23:18
Joined
Jun 20, 2003
Messages
6,423
Does any code work, if you open the from the Objects panel, i.e. not opening it from Design View? When someone moves up to a new version and code doesn't work I always wonder if they've set the file Folder as Trusted. Code will run if going from Design View to Form View, but not if you open the Form from the Objects panel, until the Folder is Trusted.

Linq ;0)>
 

hfl

Registered User.
Local time
Today, 05:18
Joined
Sep 17, 2015
Messages
31
Yes, everything works except for "form on mouse move event" and file folder is set to trusted :)
 

isladogs

MVP / VIP
Local time
Today, 04:18
Joined
Jan 14, 2017
Messages
18,261
I use mouse move events in both 2010 & 2016 without issues though not in the way you do.
I don't have 2013 but doubt that's the cause.


Check that the event hasn't got 'detached' from the button.
In other words check its listed in the property sheet.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:18
Joined
May 7, 2009
Messages
19,246
you are testing if ActiveControl (specifically command button) on
your function/sub.

what if none is active, or active control
is textbox/combobox.

the place you should look is the mousemove
envent of the Command Button. it is there
that you want to trigger.
 

hfl

Registered User.
Local time
Today, 05:18
Joined
Sep 17, 2015
Messages
31
@ridders
It's not 'detached' from the property sheet.

@arnelgp
The whole point of the code is so I don't have to have a code for each button on the form. Some of my forms can have like 40-50 buttons so that's why I made the code the way it is and it worked perfect in 2007...


Did some testing...

Detail_MouseDown event only works if I left click on open space on the form, don't work if I left click on buttons.

From_MouseDown event don't work anywhere on the form.

Form_MouseMove event don't work anywhere on the form.

Form_MouseWheel event works everywhere on the form but I have to click on a button with left mouse and then scroll to get the "Call MouseUI(me)" code to work.

https://pasteboard.co/GNkp31M.png
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:18
Joined
May 7, 2009
Messages
19,246
check this demo.

see the MouseMove event of
each button on Form TestForm.

is this so hard for you to
type.

forget about A2007, if the code
is running, then that is a bug
in A2007.

You are using ActiveControl.
and on my understanding your
buttons does Not have the
Focus, so it is not the
ActiveControl.

Therefore the behaviour in A2013
is but right.
 

Attachments

  • aaMouseMove.zip
    27 KB · Views: 189

isladogs

MVP / VIP
Local time
Today, 04:18
Joined
Jan 14, 2017
Messages
18,261
I'm not at my computer and so haven't checked Arnel's solution.
However he's correct about the focus issue.

Have a look at my text to speech example database which extensively uses mouse move events to see how I achieved something similar to what you want.
https://www.access-programmers.co.uk/forums/showthread.php?t=296135

Part of the approach I used involved
1. Adding code to ensure the button mouse move code only triggered once whilst over each button

2. having a mouse move event on the form detail which effectively cancelled the button mouse move code
 

hfl

Registered User.
Local time
Today, 05:18
Joined
Sep 17, 2015
Messages
31
Thanks but using the code like that will make it very hard to navigate the form when there is 40-50 buttons and every time you hover over a button it will open a new form...

Why is it a bug in 2007 and not 2013? The "form on mouse" events works in 2007 but do nothing in 2013 so wouldn't the bug be in 2013 as why would they put in events that can't be started...?

edit-

I see I might have explained my problem a bit poorly in my first post :(

In 2007 with the code I have I could left click on the button I wanted to open in a new form without having a click event on the button itself and nothing would happen by just hovering over it.

edit-

@ridders

Looking at your example now but is missing the Microsoft Speech Object Library reference so trying to fix that now :)
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:18
Joined
May 7, 2009
Messages
19,246
Then move the code from mousemive to click event
 

hfl

Registered User.
Local time
Today, 05:18
Joined
Sep 17, 2015
Messages
31
That don't work unless I want to add the code to every single button on the form and like I said earlier some of my forms have 40-50 buttons...

Thanks for trying to help me tho :)
 

isladogs

MVP / VIP
Local time
Today, 04:18
Joined
Jan 14, 2017
Messages
18,261
Did you look at my example using TTS?
if you haven't sorted out the library ref just look at the underlying code.
 

hfl

Registered User.
Local time
Today, 05:18
Joined
Sep 17, 2015
Messages
31
Yes, thanks for the example, had some other work stuff I had to take care of first :)

If I read the example right it needs code in the on click event on all buttons to work and that is what I want to avoid...
 

isladogs

MVP / VIP
Local time
Today, 04:18
Joined
Jan 14, 2017
Messages
18,261
No.
There are two separate bits of code.
Click event is playing the sample text which isn't relevant to you and can be ignored by you.

The mouse move related items are being used for a different purpose.
In this case to play the control tip text
Hope that makes sense
 

hfl

Registered User.
Local time
Today, 05:18
Joined
Sep 17, 2015
Messages
31
But how do I get the control tip text to play only when I click the button, not when hoovering over it?

Not sure if you have seen it but I didn't explain my problem well enough in my first post and I am sorry about that so I edited my post earlier today...
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:18
Joined
May 7, 2009
Messages
19,246
instead of waiting for others
to save you from this,
you can try copy and paste:

=MouseUI(1)

to each button's click event
replacing each number in parenthesis
with correct id.

you are not actually codeing the
click event. you are just saying
that when you press the button
run MouseUI().

believe me it won't take much of
your valuable time doing it.
unless you are too busy, lazy
and always saying "its 50 buttons
or more".
by the way, having
50 buttons is not a good idea.
you can just have a double-click
event on the form/subform id to
bring up the InstrumentInfo form
on the correct ID.
 

hfl

Registered User.
Local time
Today, 05:18
Joined
Sep 17, 2015
Messages
31
arnelgp: Thanks, didn't think to move it to the on click event outside VBA like that but still is more work than it was in A2007 but so far the best solution so thanks again :)

Added an attachment to one of my forms, it's a form that shows equipment that needs calibration. Yes, I also have a list but with the colors it's much easier to see if everything is fine or if it needs calibration :)
 

Attachments

  • formexample.PNG
    formexample.PNG
    96.2 KB · Views: 163
  • formexample2.PNG
    formexample2.PNG
    98.5 KB · Views: 121
Last edited:

isladogs

MVP / VIP
Local time
Today, 04:18
Joined
Jan 14, 2017
Messages
18,261
If I were you, I would completely redesign your form using several cascading combo boxes

1. choose from the 4 items at the top of the form
2. Choose a date
3. Choose one of the Norbar items for that date

This would be:
a) MUCH simpler for your users
b) MUCH easier to code
c) enable new items to be added as necessary without any additional code

BTW Your last reply to me made no sense.
I thought the whole point of this was that you wanted to avoid clicking so many buttons
If you redesign the form, its solved anyway ....
 

hfl

Registered User.
Local time
Today, 05:18
Joined
Sep 17, 2015
Messages
31
@ridders

Again, sorry for not explaining my problem well enough at the start... :(

So I want to click the buttons but not type any code for each button that I want to click.

The form is just a fast overview of some of the equipment we have, green = good, yellow = calibration in 30 days or less, red = over due.

At the beginning I only had equipment like in formexample2 (previous post) where new equipment wouldn't get added to that form unless something broke and had to be replaced but the database have grown a bit since then :p

Also as you see from the attachment under some equipment can have a lot more info than just name and date :)
 

Attachments

  • formexample3.jpg
    formexample3.jpg
    110.7 KB · Views: 151

isladogs

MVP / VIP
Local time
Today, 04:18
Joined
Jan 14, 2017
Messages
18,261
Again, sorry for not explaining my problem well enough at the start...

So I want to click the buttons but not type any code for each button that I want to click.

That sounds totally different to what you said originally!
Anyway, I'm suggesting a different type of form to replace your 50 or so buttons form. I think your end users will thank you of you take my advice

The second form is a much 'cleaner' design
What I'm suggesting is redesigning the first form so you get rid of all those buttons
 

Users who are viewing this thread

Top Bottom