Getting Active Control During Current Event
Getting Active Control During Current Event
am 20.11.2007 15:49:39 von DM McGowan II
I have some code in my form's On Current event which changes focus to a
particular control. I want the control to remain where it was when the user
moved to the new record. But using Screen.ActiveControl or Me.ActiveControl
in the OnCurrent event results in the error "the expression you entered
requires the control to be in the active window" (2474).
How can I determine the control that had the focus before moving to the new
record, so that I can change it back there afterwards? Thanks!
Re: Getting Active Control During Current Event
am 20.11.2007 16:06:04 von NOSPAM_djsteele
I think what you actually want is Screen.PreviousControl
--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Neil" wrote in message
news:7uC0j.18930$4V6.15503@newssvr14.news.prodigy.net...
>I have some code in my form's On Current event which changes focus to a
>particular control. I want the control to remain where it was when the user
>moved to the new record. But using Screen.ActiveControl or Me.ActiveControl
>in the OnCurrent event results in the error "the expression you entered
>requires the control to be in the active window" (2474).
>
> How can I determine the control that had the focus before moving to the
> new record, so that I can change it back there afterwards? Thanks!
>
Re: Getting Active Control During Current Event
am 21.11.2007 06:20:18 von DM McGowan II
Hmm, interesting thought. So if the focus is in CtrlA, and then the user
moves to another record, you're saying that it leaves CtrlA and goes
somewhere else while it's in the Current event, and then returns to CtrlA
when it gets to the new record?
"Douglas J. Steele" wrote in message
news:eFiqgb4KIHA.4752@TK2MSFTNGP05.phx.gbl...
>I think what you actually want is Screen.PreviousControl
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no e-mails, please!)
>
>
> "Neil" wrote in message
> news:7uC0j.18930$4V6.15503@newssvr14.news.prodigy.net...
>>I have some code in my form's On Current event which changes focus to a
>>particular control. I want the control to remain where it was when the
>>user moved to the new record. But using Screen.ActiveControl or
>>Me.ActiveControl in the OnCurrent event results in the error "the
>>expression you entered requires the control to be in the active window"
>>(2474).
>>
>> How can I determine the control that had the focus before moving to the
>> new record, so that I can change it back there afterwards? Thanks!
>>
>
>
Re: Getting Active Control During Current Event
am 21.11.2007 13:23:49 von Rick Brandt
Neil wrote:
> Hmm, interesting thought. So if the focus is in CtrlA, and then the
> user moves to another record, you're saying that it leaves CtrlA and
> goes somewhere else while it's in the Current event, and then returns
> to CtrlA when it gets to the new record?
Are you wanting move the focus smewhere else and then move it back to the
control that previously had focus? For what purpose?
If you just want the current control to keep focus as you navigate that is the
normal behavior for an Access form. If focus is moving it is because you have a
macro or code that is causing it to do so.
--
Rick Brandt, Microsoft Access MVP
Email (as appropriate) to...
RBrandt at Hunter dot com
Re: Getting Active Control During Current Event
am 21.11.2007 15:14:58 von DM McGowan II
No, neither of the below are true. The control is not losing the focus when
I move to a new record. What I had written in my original post was that
using screen.activecontrol during the OnCurrent event results in an error.
That's all.
There are *occasions* when my OnCurrent event will perform an action that
will cause the focus to move. I am aware of that and I know what that action
is. What I want to do, if that action is called, is to store the identity of
the active control before that code is called, and then restore it after the
code that causes the focus to change is executed. But when I try to store
the value of the active control in the OnCurrent event, I get the error I
noted in my original post.
Thanks,
Neil
"Rick Brandt" wrote in message
news:prV0j.73178$Um6.30266@newssvr12.news.prodigy.net...
> Neil wrote:
>> Hmm, interesting thought. So if the focus is in CtrlA, and then the
>> user moves to another record, you're saying that it leaves CtrlA and
>> goes somewhere else while it's in the Current event, and then returns
>> to CtrlA when it gets to the new record?
>
> Are you wanting move the focus smewhere else and then move it back to the
> control that previously had focus? For what purpose?
>
> If you just want the current control to keep focus as you navigate that is
> the normal behavior for an Access form. If focus is moving it is because
> you have a macro or code that is causing it to do so.
>
> --
> Rick Brandt, Microsoft Access MVP
> Email (as appropriate) to...
> RBrandt at Hunter dot com
>
>
Re: Getting Active Control During Current Event
am 21.11.2007 16:35:13 von Anthos
One thing to be aware of is that a popup form can't be referenced
through screen. (activeform or activecontrol) this will produce an
error.
The other thing is that you can't be in the VBA window when you run
this code (because the control doesn't have focus)
Use the Debug.Print to determine if it had the right focus when it ran
your code.
The Screen.ActiveControl.Name should provide you with the name of the
control.
Regards
Anthony Moore
Re: Getting Active Control During Current Event
am 21.11.2007 20:54:08 von DM McGowan II
Yes, it's not a pop-up form, and I am using debug.print
screen.activecontrol.name. That's the line that's generating the error.
Well, maybe it's something in my code. I'll look a little deeper.
"Anthos" wrote in message
news:20d0d85a-ecbe-4be3-8ded-f58fd2f9cd8c@y5g2000hsf.googleg roups.com...
> One thing to be aware of is that a popup form can't be referenced
> through screen. (activeform or activecontrol) this will produce an
> error.
> The other thing is that you can't be in the VBA window when you run
> this code (because the control doesn't have focus)
>
> Use the Debug.Print to determine if it had the right focus when it ran
> your code.
>
> The Screen.ActiveControl.Name should provide you with the name of the
> control.
>
> Regards
> Anthony Moore
Re: Getting Active Control During Current Event
am 22.11.2007 01:53:43 von Anthos
Is it a subform?
Re: Getting Active Control During Current Event
am 22.11.2007 03:04:53 von DM McGowan II
No, it's just a regular form, with no subforms in it, even, and there's no
pop-up form open or anything. Just a plain ole form.
"Anthos" wrote in message
news:f17b6f07-69d4-4d60-bb38-56eaba011dd5@s6g2000prc.googleg roups.com...
> Is it a subform?