Return Name of Object with Current Focus

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I use VB code to return the name of the object on a form that has the
focus?

I each text box on my form to highlight when the user selects it, and return
to a white background when the user selects the next text box. I know that I
could create code for each text box on Got Focus and Lost Focus, but I am
trying to see if I can do it with less code. Is there a function/method that
returns the name of the the object on a form that has the focus?
 
Rani said:
How do I use VB code to return the name of the object on a form that has the
focus?

I each text box on my form to highlight when the user selects it, and return
to a white background when the user selects the next text box. I know that I
could create code for each text box on Got Focus and Lost Focus, but I am
trying to see if I can do it with less code. Is there a function/method that
returns the name of the the object on a form that has the focus?


You can use Me.ActiveControl to reference the control with
the focus.

But, there is a way to do this without using any code.
Create a Rectangle control with a White BackColor for each
text box. Copy the text box's Top, Left, Height and Width
properties to the rectangle's properties. Use Format - Send
to Back to put the rectangle behind the text box.

Next, set the text box's BackColor property to the color you
want to use to highlight the control when it has the focus.
Last (not earlier), set the text box's BackStyle property to
Transparent.
 
Back
Top