ActiveControl returns "wrong" value if ctrl is on a multipage ctrl

D

Dale Fye

I have a userform that contains a multipage control. Each of the pages of
this control has several other controls on it. I'm adding a help key
functionality to my form that pops up a help message whenever the user hits
the F1 key while a control has the focus. The code I was implementing to do
this is:

Call HelpMsg(Me.ActiveControl.Name)

Unfortunately, if the control with the focus is on one of these multipage
controls, Me.ActiveControl.Name returns then name of the multi-page control,
not the text, list, or combo that is on that control. I can obviously hard
code the name of the control as the parameter, but it is easier to copy and
paste the same code over and over again. Is there another techique that will
provide the name of the control that actually has the focus?

Dale
 
J

Jim Cone

Dale,
You need the active control on the active page...
Me.MultiPage1.SelectedItem.ActiveControl
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(Excel Add-ins / Excel Programming)


"Dale Fye"
wrote in message I have a userform that contains a multipage control. Each of the pages of
this control has several other controls on it. I'm adding a help key
functionality to my form that pops up a help message whenever the user hits
the F1 key while a control has the focus. The code I was implementing to do
this is:
Call HelpMsg(Me.ActiveControl.Name)
Unfortunately, if the control with the focus is on one of these multipage
controls, Me.ActiveControl.Name returns then name of the multi-page control,
not the text, list, or combo that is on that control. I can obviously hard
code the name of the control as the parameter, but it is easier to copy and
paste the same code over and over again. Is there another techique that will
provide the name of the control that actually has the focus?
Dale
 
A

Andy Pope

Hi,

Modify your routine to accept an object rather than text and then test that
object for type.
If it's one of the container types re call the routine with the
activecontrol of the container.

Sub HelpMsg(Ctl As Object)
If TypeOf Ctl Is MultiPage Then
HelpMsg Ctl.Pages(Ctl.Value).ActiveControl
ElseIf TypeOf Ctl Is Frame Then
HelpMsg Ctl.ActiveControl
Else
MsgBox Ctl.Name
End If
End Sub

The actual call to the routine will also require changing.

Call HelpMsg(ActiveControl)

Cheers
Andy
 
D

Dale Fye

Andy,

Very elegant. Thanks.

--
Email address is not valid.
Please reply to newsgroup only.


Andy Pope said:
Hi,

Modify your routine to accept an object rather than text and then test that
object for type.
If it's one of the container types re call the routine with the
activecontrol of the container.

Sub HelpMsg(Ctl As Object)
If TypeOf Ctl Is MultiPage Then
HelpMsg Ctl.Pages(Ctl.Value).ActiveControl
ElseIf TypeOf Ctl Is Frame Then
HelpMsg Ctl.ActiveControl
Else
MsgBox Ctl.Name
End If
End Sub

The actual call to the routine will also require changing.

Call HelpMsg(ActiveControl)

Cheers
Andy
 

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