Highlighting a Text Box

R

Rush

I would like to know how to change the background color of a text box that
has focus, but the thing is I have a lot of text boxes. I want to avoid
going to the "On Got Focus" and "On Lost Focus" for every text box. How can
I write a macro or a piece of code that will work regardless of the name of
the text box? All these text boxes are on the same form.
Thanks in advance
 
D

Douglas J. Steele

Create a function (not a sub) that changes Screen.ActiveControl.

Select all the text boxes for which you want this apply at once, then go
into the Properties window. Set the OnGotFocus and OnLostFocus properties to
call that function you just created.
 
D

Dirk Goldgar

Rush said:
I would like to know how to change the background color of a text box
that has focus, but the thing is I have a lot of text boxes. I want
to avoid going to the "On Got Focus" and "On Lost Focus" for every
text box. How can I write a macro or a piece of code that will work
regardless of the name of the text box? All these text boxes are on
the same form.
Thanks in advance

A code-free alternative to this is to set each text box's BackColor to
the highlight color, but set its BackStyle to Transparent, and also
place a rectangle directly behind each text box, sized to match the text
box, with its BackColor property set to the "non-highlight" color and
its BackStyle property set to Normal. When a text box has the focus,
you'll see its own BackColor (the "highlight" color), but when it
doesn't, you'll see the "non-highlight" color of the rectangle behind
it.
 
Top