userform1.activecontrol.name

  • Thread starter Thread starter Italian Job
  • Start date Start date
I

Italian Job

Msgbox Userform1.ActiveControl.name

Does or should this work with controls on a multipage form? When I use it,
all I get is "frame1". No matter which control is selected
 
If the control is contained within a frame control the Frame will be
the active control, which will in turn have its own ActiveControl.
This code should resolve in the active control nested within frames:

Dim Ctrl As MSForms.Control
Set Ctrl = Me.ActiveControl
Do Until Not TypeOf Ctrl Is MSForms.Frame
Set Ctrl = Ctrl.ActiveControl
Loop
MsgBox "Active control = " & Ctrl.Name
 
Awesome. That code got me another level into it.

Unfortunately, it evaluates to "multipage1" now. I assume I should modify
the code to loop through "not Multipage" also.

Do you think I assembled this form inefficiently?
 
Awesome. That code got me another level into it.
Unfortunately, it evaluates to "multipage1" now. I assume I should modify
the code to loop through "not Multipage" also.
Yes.

Do you think I assembled this form inefficiently?

Not necessarily. Organizing controls in frames and multipages, even if
they are nested, is usually good organization from a GUI design point
of view. However, this may your code more complex. If this is the
case, consider writing some custom methods to access the controls.
 
Back
Top