How do I know if a field has focus?

J

Julia B

Hi, stupid question time but how do I determine if a field has focus as there
doesn't seem to be a focus property for fields?

What I want to do is this:

If me.txtEnterCode {doesn't have focus} then
me.txtEnterCode.SetFocus
End if

Thanks in advance.

Julia
 
D

Douglas J. Steele

The Form has an ActiveControl property, or you can simply use
Screen.ActiveControl to refer to the control.
 
L

Larry Linson

Julia B said:
Hi, stupid question time but how do I determine if
a field has focus as there doesn't seem to be a
focus property for fields?

What I want to do is this:

If me.txtEnterCode {doesn't have focus} then
me.txtEnterCode.SetFocus
End if

Question: why do you want to do this? It appears that you might think it is
more efficient.

I suspect you will find that it is equally or more efficient to just replace
the If...Then...End If with

me.txtEnterCode.SetFocus.

It works for me.

Larry Linson
Microsoft Office Access MVP
 
D

David W. Fenton

Question: why do you want to do this? It appears that you might
think it is more efficient.

I suspect you will find that it is equally or more efficient to
just replace the If...Then...End If with

me.txtEnterCode.SetFocus.

It works for me.

Hmm. Philosophically, I prefer not to do something that has no
effect, so I'd test Screen.ActiveControl, which is what the original
poster needs.

Not sure if it makes any sense or not in this context, though.
 

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