469,934 Members | 2,589 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Getting Active Control During Current Event

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!
Nov 20 '07 #1
7 4176
I think what you actually want is Screen.PreviousControl

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)
"Neil" <no****@nospam.netwrote in message
news:7u*******************@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!

Nov 20 '07 #2
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" <NOSPAM_djsteele@NOSPAM_canada.comwrote in message
news:eF**************@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" <no****@nospam.netwrote in message
news:7u*******************@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!


Nov 21 '07 #3
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
Nov 21 '07 #4
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
Nov 21 '07 #5
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" <an*****@itexcellence.com.auwrote in message
news:20**********************************@y5g2000h sf.googlegroups.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

Nov 21 '07 #6
Is it a subform?
Nov 22 '07 #7
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" <an*****@itexcellence.com.auwrote in message
news:f1**********************************@s6g2000p rc.googlegroups.com...
Is it a subform?

Nov 22 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

303 posts views Thread by mike420 | last post: by
3 posts views Thread by Atul | last post: by
3 posts views Thread by =?Utf-8?B?Q2hyaXM=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.