Format the color of textboxes and combos with criteria

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

Guest

Hi,

I have a form in continuous view to edit the records of a table of objects.
A numeric field of the table is called Group and is used to sort and show a
number of objects that belong to the same group and have the same Group No.
I would like the form to format the record textboxes or combos color in grey
and white alternately according to their Group No.
I.e. records of objects with Group No=1 in grey , objects with Group No=2 in
white, objects with Group No=3 in grey and so on.
Do you have any idea how it may done?

Thanks
GL
 
Use conditional formatting:

1. Open the form in design view.

2. Select the control(s) you want to format.

3. Choose Conditional Formatting on the Format menu.

4. Set the first condition to:
Expression ([Group No] Mod 1) = 1
and click the grey you want in the bucket icon.
 
It might be more useful to use Mod 2, of course:

Expression ([Group No] Mod 2) = 1
 
It was my fault not to mention that I open the form in many instances, one of
those is to sort objects by Group so the effect should take place in that
instance only. This makes me think I should rather use code rather than
conditional formatting that permanently formats the cells for every
instance.
Any idea on this?


Allen Browne said:
It might be more useful to use Mod 2, of course:

Expression ([Group No] Mod 2) = 1

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

GL said:
I have a form in continuous view to edit the records of a table of
objects.
A numeric field of the table is called Group and is used to sort and show
a
number of objects that belong to the same group and have the same Group
No.
I would like the form to format the record textboxes or combos color in
grey
and white alternately according to their Group No.
I.e. records of objects with Group No=1 in grey , objects with Group No=2
in
white, objects with Group No=3 in grey and so on.
 
Actually, I would be more likely to trust CF than code for multiple
instances.

There are actually cases where Access fails to understand Me correctly, and
you would think it could not get that wrong! The particuar bug where I've
seen this was applying a filter to a report instance in its Open event, such
as:
Me.Filter = "Inactive = False"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

GL said:
It was my fault not to mention that I open the form in many instances, one
of
those is to sort objects by Group so the effect should take place in that
instance only. This makes me think I should rather use code rather than
conditional formatting that permanently formats the cells for every
instance.
Any idea on this?


Allen Browne said:
It might be more useful to use Mod 2, of course:

Expression ([Group No] Mod 2) = 1

GL said:
I have a form in continuous view to edit the records of a table of
objects.
A numeric field of the table is called Group and is used to sort and
show
a
number of objects that belong to the same group and have the same Group
No.
I would like the form to format the record textboxes or combos color in
grey
and white alternately according to their Group No.
I.e. records of objects with Group No=1 in grey , objects with Group
No=2
in
white, objects with Group No=3 in grey and so on.
 
Thanks for your effort to help.
Please let me set one more question.
Is there any safe way to activate or deactivate CF on demand through the form?


Allen Browne said:
Actually, I would be more likely to trust CF than code for multiple
instances.

There are actually cases where Access fails to understand Me correctly, and
you would think it could not get that wrong! The particuar bug where I've
seen this was applying a filter to a report instance in its Open event, such
as:
Me.Filter = "Inactive = False"

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

GL said:
It was my fault not to mention that I open the form in many instances, one
of
those is to sort objects by Group so the effect should take place in that
instance only. This makes me think I should rather use code rather than
conditional formatting that permanently formats the cells for every
instance.
Any idea on this?


Allen Browne said:
It might be more useful to use Mod 2, of course:

Expression ([Group No] Mod 2) = 1


I have a form in continuous view to edit the records of a table of
objects.
A numeric field of the table is called Group and is used to sort and
show
a
number of objects that belong to the same group and have the same Group
No.
I would like the form to format the record textboxes or combos color in
grey
and white alternately according to their Group No.
I.e. records of objects with Group No=1 in grey , objects with Group
No=2
in
white, objects with Group No=3 in grey and so on.
 
Not sure what you mean by "safe" or "activate".

You can programmatically assign the properties of the FormatCondition, so I
guess you could "deactivate" it by setting the BackColor to white or some
such.

There are some issues with CF, particularly with calculated controls. If
that's what you mean by "safe", see:
http://allenbrowne.com/bug-05.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

GL said:
Thanks for your effort to help.
Please let me set one more question.
Is there any safe way to activate or deactivate CF on demand through the
form?


Allen Browne said:
Actually, I would be more likely to trust CF than code for multiple
instances.

There are actually cases where Access fails to understand Me correctly,
and
you would think it could not get that wrong! The particuar bug where I've
seen this was applying a filter to a report instance in its Open event,
such
as:
Me.Filter = "Inactive = False"

GL said:
It was my fault not to mention that I open the form in many instances,
one
of
those is to sort objects by Group so the effect should take place in
that
instance only. This makes me think I should rather use code rather than
conditional formatting that permanently formats the cells for every
instance.
Any idea on this?


:

It might be more useful to use Mod 2, of course:

Expression ([Group No] Mod 2) = 1


I have a form in continuous view to edit the records of a table of
objects.
A numeric field of the table is called Group and is used to sort and
show
a
number of objects that belong to the same group and have the same
Group
No.
I would like the form to format the record textboxes or combos color
in
grey
and white alternately according to their Group No.
I.e. records of objects with Group No=1 in grey , objects with Group
No=2
in
white, objects with Group No=3 in grey and so on.
 
Back
Top