Solved How to read a contolname (1 Viewer)

Lampje

Member
Local time
Today, 14:47
Joined
Jul 20, 2021
Messages
31
Dear Forum,

is it possible to read out the name of the control by mouseover, via a procedure or something similar.

Normally this is possible with for example:

Code:
Private Sub s1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)


Dim ht As String


ht = Forms("frmSegFin").controls("S1").Name

But i want to read straight away the name from

Private Sub s1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)

Greeting.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:47
Joined
May 7, 2009
Messages
19,237
you hardcode it:

ht="s1"
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 22:47
Joined
Jan 20, 2009
Messages
12,852
Sounds like you want to know which control the pointer is over.

Rather than create a MouseOver Event Sub for every control you can create a function and apply it as a the MouseOver Event expression to all the controls on the form. This assignment can be done using a loop through the Form's Controls Collection.

Another enhancement is to add all the controls to a Class that collects the Events and presents as a single Event from the Class instance. It can be done with multiple different events presenting the Control and Event name to any listener.
 
Last edited:

Lampje

Member
Local time
Today, 14:47
Joined
Jul 20, 2021
Messages
31
Arnelgp,
thank you for the reply, but i don't to hardcode it.

Galaxiom,
thank you for the reply, i think you understabd what i mean.
I have 200 controls on my form.
Can you give an example?

Greeting.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 22:47
Joined
Jan 20, 2009
Messages
12,852
I have 200 controls on my form.
That is a lot of Controls on a form. It is an unlikely large number in a normalized database. Can you tell us why there are so many?
 

Lampje

Member
Local time
Today, 14:47
Joined
Jul 20, 2021
Messages
31
Galaxiom,

it represent a place in a small theater.

Greeting.
 

Saphirah

Active member
Local time
Today, 14:47
Joined
Apr 5, 2020
Messages
163
Galaxiom,

it represent a place in a small theater.

Greeting.
An example would be the following:

First create a VBA Function:

Code:
Public Sub ClickedSeat(SeatName As String)
    'Your code here
End Sub

In your Forms Open Method do the following:
Code:
For Each ctl In Me.Form.Controls
    'This will loop through all buttons. Carefull, this will replace ALL BUTTON CLICK EVENTS!
    'So if you have more buttons on the form, than the seats you may want to do an additional check here!
    If ctl.ControlType = acCommandButton Then
        ctl.OnMouseMove = "=ClickedSeat('" & ctl.Name & "')"
    End If
Next ctl
 
Last edited:

Lampje

Member
Local time
Today, 14:47
Joined
Jul 20, 2021
Messages
31
Saphirah,

thank you for the reply.

I think this doesn't work for me, because i want to get it right on mouseover.

Greeting.
 

Saphirah

Active member
Local time
Today, 14:47
Joined
Apr 5, 2020
Messages
163
Obviously. Sorry, that was my bad. I adjusted the code to replace the MouseMove Event instead.
But be carefull, OnMouseMove does fire quite a lot :D
 
Last edited:

Lampje

Member
Local time
Today, 14:47
Joined
Jul 20, 2021
Messages
31
Saphirah,

i really appreciate your attempt to help me.
Forgive my english, because i have to use a translation program.
What you are offering me is not quite what i mean.
Try explaining again. The mouseover as it intended is very important to me.
So really look for a way to read S1 in Private Sub s1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
I'm lazy and don't want to enter s1,s2 etc every time in the follow-up code.

Greeting.
 

Saphirah

Active member
Local time
Today, 14:47
Joined
Apr 5, 2020
Messages
163
Saphirah,

i really appreciate your attempt to help me.
Forgive my english, because i have to use a translation program.
What you are offering me is not quite what i mean.
Try explaining again. The mouseover as it intended is very important to me.
So really look for a way to read S1 in Private Sub s1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
I'm lazy and don't want to enter s1,s2 etc every time in the follow-up code.

Greeting.
Sadly it is impossible to just "read" the name of the current function, or the control you are using.
That's why we are using the hard coding with the for each loop.

If you want to call the functions you already have, then i have another solution for you.
This will loose the parameters though, so i hope you are not using them.
Code:
'Button, Shift, x and y won't be usable
Public Sub s1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)

Code:
Public Sub ClickedSeat(SeatName As String)
    'Calls the original MoveMove functions without any parameters
    CallByName Me.Form, SeatName & "_MouseMove", vbMethod
    'More custom code here
End Sub

Private Sub Form_Open(Cancel As Integer)
  For Each ctl In Me.Form.Controls
    'This will loop through all buttons. Carefull, this will replace ALL BUTTON CLICK EVENTS!
    'So if you have more buttons on the form, than the seats you may want to do an additional check here!
    If ctl.ControlType = acCommandButton Then
        ctl.OnMouseMove = "=ClickedSeat('" & ctl.Name & "')"
    End If
  Next ctl
End Sub

If this is not what you wanted then i do not understand your request corretly, and i am sorry for that.
Maybe an upload of a stripped database will help us solve your problem :)
 
Last edited:

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 20:47
Joined
May 7, 2009
Messages
19,237
here is a sample Class to read the control on mouse move over.
note that i "remove" the label on each textbox control to show it as "Label".
see the Status bar change when you move over each control on form1.
 

Attachments

  • dbOnMouseMoveClass.accdb
    400 KB · Views: 424

Lampje

Member
Local time
Today, 14:47
Joined
Jul 20, 2021
Messages
31
Saphirah,

i may be forgetting something, it won't work for me.

Two pairs of eyes see more than 1.

Hopefully you can help me further.


Greeting.
 

Attachments

  • DAT6Forum.accdb
    2.8 MB · Views: 298

Saphirah

Active member
Local time
Today, 14:47
Joined
Apr 5, 2020
Messages
163
Here you go. I forgot something in my code so that was my bad.
You do need to add the parameters to the MouseMove Function. I just added some 0 Values. In addition to that your MouseMove Events for the different buttons are written in lower case, and does not match with the names of the controls.
And the Methods need to be Public.

So here is a version that should work!

Like i said, with this approach you will loose the parameters, so i hope you do not depend on the mouse position or something.
But i see no other way of doing that
 

Attachments

  • DAT6Forum.accdb
    2.8 MB · Views: 425
Last edited:

Lampje

Member
Local time
Today, 14:47
Joined
Jul 20, 2021
Messages
31
Saphirah,

thank you very much, this is a nice solution and gives me further options.

Greeting.
 

Users who are viewing this thread

Top Bottom