Determine ActiveControl on a multipage (tab) control

D

Dale Fye

How can I determine what the "ActiveControl" is when the control is on a
multipage (tab) control?

Is there a way to iterate through the control on the multipage tab and
determine which one has the focus?

Dale
 
D

deepakvenkatesan123

create a form/sheet level variable and in the tab click event set it
to the tab number clicked.
 
D

Dale Fye

Sorry, I probably wasn't clear enough.

I've got a bunch of textboxes on a multipage control. Have a function that
I want to work based on the "ActiveControl", but when I run the following
code, it indicates that the "ActiveControl" is the multipage control, rather
than the textbox that actually has the focus.

I need to determine which textbox has the focus.

Dale
 
D

deepakvenkatesan123

isn't there a GotFocus event for the textboxes? Just put code in each
of the got focus events, for every single control, that sets the
ControlHasFocus variable to the name or Index of the control. That's
how I would do it anyway.
 
R

Rick Rothstein \(MVP - VB\)

Sorry, I probably wasn't clear enough.
I've got a bunch of textboxes on a multipage control. Have a function
that
I want to work based on the "ActiveControl", but when I run the following
code, it indicates that the "ActiveControl" is the multipage control,
rather
than the textbox that actually has the focus.

I need to determine which textbox has the focus.

I think this will give you what you want...

MultiPage1.SelectedItem.ActiveControl.Name

Rick
 
D

Dale Fye

Rick,

Exactly what I was looking for. What I finally ended up using is.

Set ctrl = frm.ActiveControl
While TypeOf ctrl Is msforms.MultiPage
Set ctrl = ctrl.SelectedItem.ActiveControl
Wend

Thanks!

--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 
R

Rick Rothstein \(MVP - VB\)

I'm not sure I understand why you used a While/Wend loop. Since there is
only one ActiveControl on your UserForm, and only one selected Page on the
MultiPage and only one ActiveControl on that selected Page, I don't see what
you are looping through. Of course, I don't know what the rest of your
program is doing, but (off the top of my head) it seems like this should do
what I think your code snippet is attempting to do....

Set ctrl = frm.ActiveControl
If TypeOf ctrl Is msforms.MultiPage Then
Set ctrl = ctrl.SelectedItem.ActiveControl
End If

Do the above assumes, I guess, that you have more than one MultiPage control
on your form and you want to work with whichever one is the currently
ActiveControl. If, however, you only have one MultiPage control on your
form, you should be able to set ctrl to its ActiveControl (on its selected
Page) directly like this...

Set ctrl = frm.MultiPage1.SelectedItem.ActiveControl

(again, that was off the top of my head and untested) where you would use
the name of your MultiPage control in place of the name MultiPage1 that I
used.

Rick
 
R

Rick Rothstein \(MVP - VB\)

Okay, I thought about what you are doing some more and think you would want
my first suggested change, not the second one. That is, I think this...

Set ctrl = frm.ActiveControl
If TypeOf ctrl Is msforms.MultiPage Then
Set ctrl = ctrl.SelectedItem.ActiveControl
End If

does what your last posted code (the one with the While/Wend loop) was
trying to do.

Rick
 
D

Dale Fye

Sorry, I didn't clarify.

It turns out that at least one of the textboxes I want to work with is on a
multipage imbedded within another multipage.

Thanks again.

Dale
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.
 

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

Top