Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing Font Color Based on Content 1

Status
Not open for further replies.

jt643

Technical User
Jun 17, 2003
144
I may be asking for the impossible. I have a subform that displays as a form that mimics a datasheet - in other words, I have the text boxes meeting each other with white background and black text - so it looks like a datasheet.

The three colomns are 'Category', 'Selection', and 'Order'.

What I want to do is to make the Font Color and Background of the three text boxes a certain format - IF the 'Category' = "A Certain Category".

In other words, I want all records that have "Electrical" as the Category to display as Red font and a Grey background.

I have selected all records from the table within my VB that have 'Electrical' as the category, but I am having a problem making the form recognize each record that shows on the form as being unique, and therefore not making them all formatted the same. I can get the font and background to change but it does so for all or none of the records.

I can paste my code if that would help.

Thank you for your time.
 
Hi
Have you looked at conditional formatting?
 
Thank you Remou.

I am not familiar with that concept. Where do I begin - is it done within VB, or is it a form property control?

Thanks for your help.
 
You can do it through VBA, but the easiest way is to use the format menu when in form design view.
 
Thanks Remou! Is it possible to apply a second condition?

In other words, if I want two 'Categories' to produce a certain format, can I add a condition, and if so - how?
 
It's a bit late so I am even dimmer than usual. You can add a second condition to the same field by clicking Add in the format conditional window, you can format conditional across a whole row with an expression. If I have not drifted across what you want, please explain a little more. :)
 
Remou, you have provided me with exactly what I needed. Thank you.

I think that I have what I need, but if you would be willing to tell me how I can apply a conditional format across a whole row with an expression, that may come in handy for the future.

In addition, do you know how to change the conditional default format of a field? I want my field to not have a background if the condition is not met, but the default format has a grey background. I changed it to white by clicking the background icon, but it only changes the icon and not the actual field background.

Thanks so much for your time Remou!
 
I figured out that just because the default box on conditional formatting shows a grey background does not mean that is how the record will actually display.
 
Click at the edge of the row to select all the boxes or choose a selection of boxes (make sure you do not include any command buttons). Under contional formatting choose Expression Is from the dropdown box and then type an expression into the textbox to the right of Expression Is. For example,
[OrderNo]>=0
[Type]="Electrical"

Welcome.
 
Thanks Remou.

I tried your suggestion. I get an error that says I need to specify criteria for all conditional formats.

Basically, my three text boxes are: Category, Selection, and Order.

I would like all three to have similar font color and background color - IF 'Category' is either equal to "Electrical" or "Low Voltage Systems".

I tried the following (don't laugh!):

([Category]="Electrical" Or [Category]="Low Voltage System") [Selection] Like "*" [Order]>=0

The reason I threw in [Selection] and [Order] is because I thought they would have to be there based on the error message I am getting.

Thanks so much for your help!
 
Nothing to laugh about.
This works for me:
[Category]="Electrical" Or [Category]="Low Voltage System"
With or without brackets, which is pretty much the same as your line. I have not really tried to re-create your error so here are a few guesses. Try setting the condition for the textboxes one at a time, rather than in a bunch as I suggested. This way you can check if there are other conditional formats set that may be causing a problem. Also, try if the condition works for one textbox, to help narrow this down, maybe.
 
Perfect!

Thank you Remou. You have saved me a lot of time and headaches!

I am grateful for your time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top