High light the controls

L

Leo

I have a form with number of Yes/No fields. Is there a way to highlight the
labels with a different color when the fields get focus. I am not able to use
the conditional formatting that works for the other controls. Also is there a
way to write the codes on the On Open event of the form that will make all
the controls get the above effect?

Thanks in advance
Leo
 
A

Allen Browne

See:
Highlight the required fields, or the control that has focus
at:
http://allenbrowne.com/highlight.html
There's a sample database to download and see how it works.
You can ignore the bit about 'required fields', and just follow the 'has
focus' example.

At a slightly deeper level, if you have lots of yes/no fields on your form
and therefore in your table, you may have made this common mistake in the
way you designed your table:
Don't use Yes/No fields to store preferences
at:
http://allenbrowne.com/casu-23.html
 
L

Leo

Thanks Allen. But my problem is with Yes/No fields and their Labels.
Specifically with their labels. Your method highlights only text boxes, combo
boxes, and list boxes. I could also do that with conditional formatting.

Is there any way to high light the labels of the yes/no fields when the
yes/no field gets the focus?

Thanks
Leo
 
A

Allen Browne

You could use the GotFocus and LostFocus event of each check box to set the
properties of its attached label.

The label attached to Check1 is:
Check1.Controls(0)
so, you would set its BackColor property like this:
Me.Controls("Check1").Controls(0).BackColor = vbRed

Note that this approach won't work properly in a continuous form.
 
L

Leo

Thanks again Allen. I tried as you said.
The form is Single Form and not continuous.
Control Name is Fld1
The code I inserted in got focus is as follows
Fld1.Controls(0).BackColor = vbRed
It did not work.
What am I doing wrong?
I am using Access2003

Thanks
Leo
 
L

Leo

Hi Allen

It worked ! The mistake was originally the label back color property was set
to transparent. Once I changed it to Normal then it worked.

Now is there any way that I can insert this code in the Form On Open or On
Activate property so that all the Controls ( yes/no, text fields, date fields
etc) will inherit this property so that I don't have to individually type
this code for each control?

Thanking you again
Sincerely
Leo
 

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