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
Bookmarks