Any way to test if control has focus?

M

mscertified

I need to test if a control has the focus, is it possible?

The reason I need to know is I am setting focus on a mousemove event and I
only want to do it once otherwise I get flicker.
 
K

Ken Snell \(MVP\)

Test the value of Screen.ActiveControl.Name, which will tell you the name of
the control that has the focus at that moment.
 
D

Dirk Goldgar

mscertified said:
I need to test if a control has the focus, is it possible?

The reason I need to know is I am setting focus on a mousemove event
and I only want to do it once otherwise I get flicker.

Two ways I can think of:

1. Set a module-level flag variable when the control gets the focus (in
the GotFocus event), and reset it in the LostFocus event.

2. Check to see if this is the active control:

'----- warning: air code -----
Dim ctlActive As Access.Control
Dim blnMyFieldHasFocus As Boolean

On Error Resume Next
Set ctl = Me.ActiveControl

If Not (ctl Is Nothing) Then
If ctl Is Me!MyField Then
blnMyFieldHasFocus = True
End If
End If

If blnMyFieldHasFocus Then
' MyField has the focus
Else
' It doesn't.
End If
'----- end code -----
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top