Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Need active control name

Posted on 2012-04-07
Medium Priority
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?
Question by:tru-numbers
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 49

Expert Comment

by:Martin Liss
ID: 37820212
Try Screen.ActiveControl.Name

which works in VB6
LVL 42

Expert Comment

ID: 37820241


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


Author Comment

ID: 37826938
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?
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

LVL 42

Expert Comment

ID: 37828356
For a multi-page control, you can use:


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


And if the multipage is inside a frame:


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)
        Set getControl = ctrl
    End If
End Function

Open in new window

LVL 42

Accepted Solution

dlmille earned 2000 total points
ID: 37900874
@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.



Author Closing Comment

ID: 37903473
Thanks for youe assistance

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to import an Outlook PST file to Office 365 using a third party product to avoid Microsoft's Azure command line tool, saving you time.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

715 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