Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default ActiveControl returns "wrong" value if ctrl is on a multipage ctrl


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
--
Email address is not valid.
Please reply to newsgroup only.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default ActiveControl returns "wrong" value if ctrl is on a multipage ctrl

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
--
Email address is not valid.
Please reply to newsgroup only.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default ActiveControl returns "wrong" value if ctrl is on a multipage ctrl

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

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"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
--
Email address is not valid.
Please reply to newsgroup only.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default ActiveControl returns "wrong" value if ctrl is on a multipage

Andy,

Very elegant. Thanks.

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


"Andy Pope" wrote:

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

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"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
--
Email address is not valid.
Please reply to newsgroup only.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a difference between CTRL+D and CTRL+" (quotation marks) AKMMS Excel Discussion (Misc queries) 2 March 22nd 10 07:43 PM
How to Double click a blank cell to enact "ctrl + ;" Emredrum Excel Worksheet Functions 10 October 16th 08 10:30 PM
2007 - Column unhide in Excel does not work i.e. "Ctrl+shift+)" MikeElstonJones Excel Discussion (Misc queries) 3 November 28th 07 12:42 PM
Can I have "Shift-Click" or "Ctrl-Click" Code on Form List? MikeZz Excel Programming 0 June 13th 07 12:58 AM
VBA code to display the "Find" (Ctrl+F) dialog box lothario[_28_] Excel Programming 2 October 17th 03 10:28 AM


All times are GMT +1. The time now is 09:37 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"