Results 1 to 5 of 5

Return the control name of command button just clicked

Threaded View

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Return the control name of command button just clicked

    The Command Button needs to have .TakeFocusOnClick set to True

    Private Function fnstrGetFormsActiveControlName(ByRef frmForm As UserForm) As String
        Dim strResult As String
        
        If TypeOf frmForm.ActiveControl Is MSForms.Frame Then
            If TypeOf frmForm.ActiveControl.ActiveControl Is MSForms.MultiPage Then
                'strResult = frmForm.ActiveControl.ActiveControl.Pages(frmForm.ActiveControl.ActiveControl.Value).ActiveControl.Name
                strResult = frmForm.ActiveControl.ActiveControl.SelectedItem.ActiveControl.Name
            Else
                strResult = frmForm.ActiveControl.ActiveControl.Name
            End If
        ElseIf TypeOf frmForm.ActiveControl Is MSForms.MultiPage Then
            'strResult = frmForm.ActiveControl.Pages(frmForm.ActiveControl.Value).SelectedItem.Name
            strResult = frmForm.ActiveControl.SelectedItem.ActiveControl.Name
        Else
            strResult = frmForm.ActiveControl.Name
        End If
    
        fnstrGetFormsActiveControlName = strResult
    End Function
    Last edited by mc84excel; 03-24-2015 at 07:53 PM.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] How to make a Command button run the "FORM" command to fill/populate a table?
    By jrobin7 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-21-2012, 12:26 PM
  2. Form - Command Button
    By shugg24 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-27-2010, 09:28 AM
  3. Command button is not working by using VBA
    By Webtekr in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2009, 02:22 AM
  4. VB's Command Button vs Form's Command Button
    By Ronald Dodge in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-24-2006, 09:30 AM
  5. command button isn't working
    By Nydia in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 04-29-2005, 06:06 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1