How do I know if a field has focus?

  • Thread starter Thread starter Julia B
  • Start date Start date
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
 
The Form has an ActiveControl property, or you can simply use
Screen.ActiveControl to refer to the control.
 
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
 
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.
 
Back
Top