Get name of control that initiates an action

alphaex32

New member
Local time
Today, 17:08
Joined
Aug 18, 2005
Messages
7
What I need to do is get the name of a control when the mouse is over it. The problem is that I would need to make a custom macro/code for each control since there doesnt seem to be a way to retrieve the name of the control which initiated the mousemove action. Any ideas?
 
Liv Manto said:
Control Tip Text Property? in properties?--ALL
How does that help me? I dont want to display a tip, I want to retrieve the controls name...
 
Private Sub Command2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim CTLName As String

Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl
CTLName = ctlCurrentControl.Name
MsgBox "now do whatever what you want with Ctl Name " & CTLName
End Sub
 
Sounds like that is what I am looking for. Unfortunately, Im not very good with vb, so could you do me a favor and write code that would send the ControlSource of the ctlCurrentControl to a text box.
 
Private Sub Command2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim CTLName As String

Dim ctlCurrentControl As Control
Set ctlCurrentControl = Screen.ActiveControl
CTLName = ctlCurrentControl.Name
'MsgBox "now do whatever what you want with Ctl Name " & CTLName

me.myTextbox.value = CTLname
me.form.refresh
End Sub
 
For each control that you need to be included place "Include in collection" in its Tag property.

Code:
Option Explicit
Option Compare Text


Private Function DisplayControlName(ByVal strControlName As String)

    If strControlName = "Detail" Then
        Me.txtMyTextBox = ""
    Else
        Me.txtMyTextBox = Me(strControlName)
    End If

End Function


Private Sub Form_Open(ByRef intCancel As Integer)
    Dim ctl As Control
    
    Const conHandler As String = "=DisplayControlName("
    
    For Each ctl In Me
        If ctl.Tag = "Include in collection" Then
            ctl.OnMouseMove = conHandler & Chr$(34) & ctl.Name & Chr$(34) & ")"
        End If
    Next ctl
    
    Me.Section(acDetail).OnMouseMove = conHandler & Chr$(34) & "Detail" & Chr$(34) & ")"
    
End Sub

Hope that’s what you require.

Regards,
Chris.
 

Users who are viewing this thread

Back
Top Bottom