changing textbox color when selected

  • Thread starter pclis007 via AccessMonster.com
  • Start date
P

pclis007 via AccessMonster.com

Hi,

I am a little out of practice, so need a little help. I have a form with
alot of textboxes and tabs. When a user selects a textbox, I want it to
change from the generic white to yellow for example. I think there is some
code I can insert in the overall form properties that will do this. Any help
would be appreciated.

Thanks
 
A

Arvin Meyer MVP

I use a function like this in a Standard Module:

Public Function Highlight(ctl As Control, bHighlighted As Boolean)
If bHighlighted Then
ctl.BackColor = vbYellow
Else
ctl.BackColor = vbWhite
End If
End Function

The in the GotFocus event property sheet I use:

=HighLight([TextboxName],True)

and in the LostFocus event, I use:

=HighLight([TextboxName],False)

I use the last 2 function calls in every control that I want to include. It
also works just fine in listboxes and comboboxes.
 
L

Linq Adams via AccessMonster.com

For versions 2000 forward, why not use Conditional Formatting?

In Design View

Select all textboxes

Goto Format - Conditional Formatting

Under Condition select "Field has focus"

Select color from the Back Color Icon (looks like a bucket)

Click OK

This can also be used in any form view, while code can only be used to do
this kind of formatting in a Single View Form, not in Datasheet or Continuous
View Forms
 
A

Arvin Meyer MVP

Although that will work, I generally don't use Conditional Formatting mostly
because if you have more than a couple of controls to do, it will be more
work, and take longer. OTOH, Conditional Formatting is the only thing that
can be used on datasheets and continuous forms.
 
L

Linq Adams via AccessMonster.com

Arvin said:
Although that will work, I generally don't use Conditional Formatting mostly
because if you have more than a couple of controls to do, it will be more
work, and take longer.

How so? You select all the controls you want to format at one time, go into
Conditional Formatting once, set the formatting.

All of the selected controls are then formatted.
 
A

Arvin Meyer MVP

You are right. I never realized you can do them all at once. Conditional
formatting is easier.
Thanks,
 
L

Linq Adams via AccessMonster.com

That's what I find so fascinating about Access; no matter how many years you
have in it, no matter experienced you are in it, there's always something new
to learn!
 
D

David W. Fenton

I use the last 2 function calls in every control that I want to
include. It also works just fine in listboxes and comboboxes.

Huh. I think it's much easier to set the background color to
something other than the form background color (say, white), and set
it to transparent. When a control gets the focus, the background
turns white. Otherwise, the form background color shows through.
 

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