ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   userform1.activecontrol.name (https://www.excelbanter.com/excel-programming/282393-userform1-activecontrol-name.html)

Italian Job

userform1.activecontrol.name
 
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



onedaywhen

userform1.activecontrol.name
 
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


"Italian Job" wrote in message ...
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


Italian Job

userform1.activecontrol.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?


"onedaywhen" wrote in message
m...
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


"Italian Job" wrote in message

...
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




onedaywhen

userform1.activecontrol.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.


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.


"Italian Job" wrote in message ...

"onedaywhen" wrote in message
m...
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


"Italian Job" wrote in message

...
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



All times are GMT +1. The time now is 05:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com