By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,139 Members | 1,247 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,139 IT Pros & Developers. It's quick & easy.

How to identify the control that has focus?

P: n/a
Hi folks,

Screen.PreviousControl.SetFocus works fine to select the control that
had focus prior to the one that NOW has focus. Unfortunately, I've
not discovered a VBA code way to get the name of the control, that
currently has focus. It would be nice if the Screen object had a
property called "CurrentControl" that could be stored in a variable,
as in: "X = Screen.CurrentControl.Name"

Am I overlooking something?

Any advice will be appreciated.
Nov 12 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On Thu, 23 Oct 2003 13:12:31 -0500, William Case
<re**********@nospam.zap> wrote in comp.databases.ms-access:

Screen.PreviousControl.SetFocus works fine to select the control that
had focus prior to the one that NOW has focus. Unfortunately, I've
not discovered a VBA code way to get the name of the control, that
currently has focus. It would be nice if the Screen object had a
property called "CurrentControl" that could be stored in a variable,
as in: "X = Screen.CurrentControl.Name"

Am I overlooking something?


Yes. Screen.ActiveControl
Peter Miller
__________________________________________________ __________
PK Solutions -- Data Recovery for Microsoft Access/Jet/SQL
Free quotes, Guaranteed lowest prices and best results
www.pksolutions.com 1.866.FILE.FIX 1.760.476.9051
Nov 12 '05 #2

P: n/a
Screen.Activecontrol.Name

Regards

Peter Russell
William Case previously wrote:
Hi folks,

Screen.PreviousControl.SetFocus works fine to select the control that
had focus prior to the one that NOW has focus. Unfortunately, I've
not discovered a VBA code way to get the name of the control, that
currently has focus. It would be nice if the Screen object had a
property called "CurrentControl" that could be stored in a variable,
as in: "X = Screen.CurrentControl.Name"

Am I overlooking something?

Any advice will be appreciated.


Nov 12 '05 #3

P: n/a
On Thu, 23 Oct 2003 18:20:40 GMT, Peter Miller
<pm*****@pksolutions.com> wrote:
On Thu, 23 Oct 2003 13:12:31 -0500, William Case
<re**********@nospam.zap> wrote in comp.databases.ms-access:

Screen.PreviousControl.SetFocus works fine to select the control that
had focus prior to the one that NOW has focus. Unfortunately, I've
not discovered a VBA code way to get the name of the control, that
currently has focus. It would be nice if the Screen object had a
property called "CurrentControl" that could be stored in a variable,
as in: "X = Screen.CurrentControl.Name"

Am I overlooking something?


Yes. Screen.ActiveControl


Thanks Peter. I just tried to do this. Screen.ActiveControl has no
Name property!
Nov 12 '05 #4

P: n/a
On Thu, 23 Oct 2003 19:26 +0100 (BST), ru***@127.0.0.1 (Peter Russell)
wrote:
Screen.Activecontrol.Name
Thanks. Unfortunately, >Screen.Activecontrol has no Name property.
It should, but it does not. Now what?
Regards

Peter Russell
William Case previously wrote:
Hi folks,

Screen.PreviousControl.SetFocus works fine to select the control that
had focus prior to the one that NOW has focus. Unfortunately, I've
not discovered a VBA code way to get the name of the control, that
currently has focus. It would be nice if the Screen object had a
property called "CurrentControl" that could be stored in a variable,
as in: "X = Screen.CurrentControl.Name"

Am I overlooking something?

Any advice will be appreciated.


Nov 12 '05 #5

P: n/a

On Thu, 23 Oct 2003 16:20:43 -0500, William Case
<re**********@nospam.zap> wrote in comp.databases.ms-access:
Thanks Peter. I just tried to do this. Screen.ActiveControl has no
Name property!


But of course it does.

Did you actually try this?

Remember that in order to use the name property, there must be an
active control. If you are testing and you don't actually have an
active control, then of course, you can't get its name.

If you're wondering why intellisense doesn't offer a name property
when the active control *does* exist, remember that activecontrol is a
placeholder or generic object pointer. It will, as a result, allow
for the use of methods and properties that are legal for the active
control, even if not common to all controls and therefore not listed
in intellisense popups.
Peter Miller
__________________________________________________ __________
PK Solutions -- Data Recovery for Microsoft Access/Jet/SQL
Free quotes, Guaranteed lowest prices and best results
www.pksolutions.com 1.866.FILE.FIX 1.760.476.9051
Nov 12 '05 #6

P: n/a
RE/

Thanks. Unfortunately, >Screen.Activecontrol has no Name property.
It should, but it does not. Now what?


It does - Microsoft is just messing with your mind in the IntelliSense dropdown.

Just try it:
-------------------------
Private Sub cmdTestActiveControl_Click()
MsgBox Screen.ActiveControl.Name, 0, "Gotcha!"
End Sub
-------------------------

One caveat: If you're running in line-by-line debugging mode, it will fail
because the code window is active.
--
PeteCresswell
Nov 12 '05 #7

P: n/a
x@y.z ((Pete Cresswell)) wrote in
<re********************************@4ax.com>:
RE/

Thanks. Unfortunately, >Screen.Activecontrol has no Name
property. It should, but it does not. Now what?


It does - Microsoft is just messing with your mind in the
IntelliSense dropdown.

Just try it:
-------------------------
Private Sub cmdTestActiveControl_Click()
MsgBox Screen.ActiveControl.Name, 0, "Gotcha!"
End Sub
-------------------------

One caveat: If you're running in line-by-line debugging mode, it
will fail because the code window is active.


Not in Access 2000.

--
David W. Fenton http://www.bway.net/~dfenton
dfenton at bway dot net http://www.bway.net/~dfassoc
Nov 12 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.