Solved

Need active control name

Posted on 2012-04-07
6
463 Views
Last Modified: 2012-04-27
From a field on a excel form  (excel 2003),  I would like to get the active field name.  Can anyone help?
0
Comment
Question by:tru-numbers
  • 3
  • 2
6 Comments
 
LVL 45

Expert Comment

by:Martin Liss
Comment Utility
Try Screen.ActiveControl.Name

which works in VB6
0
 
LVL 41

Expert Comment

by:dlmille
Comment Utility
Use:

Me.ActiveControl.name

or:

Userform1.ActiveControl.Name (replace Userform1 with the name of your userform)

Dave
0
 

Author Comment

by:tru-numbers
Comment Utility
Yes, this works! But I have a control on a multipage control.  How do I obtain the active control when the user clicks on a field within the multipage?
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 41

Expert Comment

by:dlmille
Comment Utility
For a multi-page control, you can use:

Me.ActiveControl.Object.SelectedItem.ActiveControl.Name

Or, you could use (where MultiPage1 is the name of your multipage control):

Me.MultiPage1.Pages(Me.MultiPage1.Value).ActiveControl.Name

And if the multipage is inside a frame:

Me.MultiPage1.Pages(Me.MultiPage1.Value).Frame1.ActiveControl.Name

If you don't know where the control might be you can try this code, which I just tested in a bunch of nested frames, tab strips, and multipage controls, to get the name of a checkbox control I clicked on the click event:

Sub getActiveControl()
Dim actCtrl As Control

    Set actCtrl = getControl(Me.ActiveControl)
    MsgBox actCtrl.Name
    
End Sub
Function getControl(ctrl As Control) As Control

    If TypeOf ctrl Is MSForms.Frame Then
        Set getControl = getControl(ctrl.ActiveControl)
    ElseIf TypeOf ctrl Is MSForms.MultiPage Then
        Set getControl = getControl(ctrl.Object.SelectedItem.ActiveControl)
    Else
        Set getControl = ctrl
    End If
End Function

Open in new window

0
 
LVL 41

Accepted Solution

by:
dlmille earned 500 total points
Comment Utility
@tru-numbers - did you have success with the code I posted?  Please advise if more assistance is needed.  The code, above, is tested and works.  If you need a demonstration workbook leveraging this code as more of an example, just ask.

Cheers,

Dave
0
 

Author Closing Comment

by:tru-numbers
Comment Utility
Thanks for youe assistance
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In case Office 2010 has not been deployed in your environment, this article may be quite useful. In our office, we wanted a way to deploy Microsoft Office Professional Plus 2010 through an automated batch file via logon script. This article is docum…
In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now