PC Review


Reply
Thread Tools Rate Thread

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

 
 
=?Utf-8?B?RGFsZSBGeWU=?=
Guest
Posts: n/a
 
      15th Oct 2007

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 With Quote
 
 
 
 
Jim Cone
Guest
Posts: n/a
 
      15th Oct 2007
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.
 
Reply With Quote
 
Andy Pope
Guest
Posts: n/a
 
      15th Oct 2007
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" <(E-Mail Removed)> wrote in message
news:F7967C41-DB9B-4479-9F13-(E-Mail Removed)...
>
> 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 With Quote
 
=?Utf-8?B?RGFsZSBGeWU=?=
Guest
Posts: n/a
 
      15th Oct 2007
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" <(E-Mail Removed)> wrote in message
> news:F7967C41-DB9B-4479-9F13-(E-Mail Removed)...
> >
> > 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is there a difference between CTRL+D and CTRL+" (quotation marks) AKMMS Microsoft Excel Misc 2 22nd Mar 2010 07:43 PM
How to realize "Format Sections" like one in VS IDE (Ctrl+K, Ctrl+ =?Utf-8?B?TWljaGFlbCBOZW10c2V2?= Microsoft C# .NET 0 27th Feb 2006 02:01 PM
Re: Popups: "Ctrl to override" does not work in the "High: Block all pop-ups" setting of new SP2 Pop-up Blocker Richard A. Landkamer Windows XP General 1 30th Nov 2004 07:07 PM
"Ctrl to override" does not work in "High: Block all pop-ups" setting of new SP2 Pop-up Blocker Richard A. Landkamer Windows XP Internet Explorer 0 14th Sep 2004 07:30 AM
"Ctrl to override" does not work in "High: Block all pop-ups" setting of new SP2 Pop-up Blocker Richard A. Landkamer Windows XP General 0 6th Sep 2004 11:26 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:56 PM.