Focus

  • Thread starter Thread starter Roy Miller
  • Start date Start date
R

Roy Miller

I suspect this is possible to do in VBA but I am at a loose end on ho
it is done.

On a userForm that has multiple objects in multiple frames, is i
possible to find out which object at any particular time, irrespectiv
of which frame it is in, has currently got the focus ?

Any ideas?

Thanks in advance

R
 
Hi RM

In theory (this demo click the form surface outside controls to run):

Private Sub UserForm_Click()
MsgBox Me.ActiveControl.Name
End Sub

Problems arise when you use containers, frames and multipages, which I
understand youn will. They will be the active control and you have to dig
for THEIR active control. The approach would be like this

Private Sub UserForm_Click()
On Error Resume Next
MsgBox Me.ActiveControl.Name
MsgBox Me.Controls(Me.ActiveControl.Name).ActiveControl.Name
End Sub

now you decide how many levels deep are needed and which errors to trap if
there are fewer levels when you search. Problem is probably not that big
when you know what this is for and when it's gonna run.

HTH. Best wishes Harald
 
This looks about right, I will try it out when I get back off holiday.

Roy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top