Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Need active control name

Posted on 2012-04-07
6
Medium Priority
?
562 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 49

Expert Comment

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

which works in VB6
0
 
LVL 42

Expert Comment

by:dlmille
ID: 37820241
Use:

Me.ActiveControl.name

or:

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

Dave
0
 

Author Comment

by:tru-numbers
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?
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 42

Expert Comment

by:dlmille
ID: 37828356
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 42

Accepted Solution

by:
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.

Cheers,

Dave
0
 

Author Closing Comment

by:tru-numbers
ID: 37903473
Thanks for youe assistance
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
Quickbooks hosting can do wonders to your enterprise but considering the points elaborated in the article which will help you to better analyze the outcomes. So scan your business, its needs and then move to the new world of limitless benefits.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

916 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