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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Textbox Color 1

Status
Not open for further replies.

mach27

Technical User
Oct 25, 2005
18
0
0
Hello Experts

My question is how to change the color of the textbox based on the value of another textbox?

Example:
Textbox color of 'AOP' field will change to 'Red' whenever there is no value in 'ROP' field.

regards,
[morning]
 
Hi Duane

Conditional Formatting is limited to the value or expression (formula used) of a certain textbox. What I want to do is that the textbox color of a certain field will be dependent to the value of another textbox.

[smile]

Regards,
 
Conditional formatting in Access allows you to use and expression that references other controls/fields. Your expression could be something like:
IsNull([ROP])

Duane
Hook'D on Access
MS Access MVP
 
Got it Duane, thanks [medal]

Is there a way it can be transformed into a code? There are a lot of text boxes that it will be applied, doing it one by one will make it hard for me to track once there are changes to be made.

::)
 
If you have lots of these to do, I would consider using code in the On Format event of the report section containing the controls.
Code:
Me.txtAOP.ForeColor = IIf(IsNull(Me.txtROP), 255,0)
You can loop through controls it this code gets too repetitive.

Duane
Hook'D on Access
MS Access MVP
 
Thanks Duane,

it works [medal]

regards,
[glasses]
 
Duane,

How would I modify this code to use in MS Access 2007?

I tried editing the code to:
NFL-Master.Title.ForeColor = IIf((NFL - Master.Name) Like "Bob Waterfield", 255, 0)

NFL-Master is my table name, Title and Name are fields within that table.

Thank you, in advance, for your help.

Peggy
 
Duane,

Sorry... a modification on the question...

I was just using the code to try to test it out in my particular report. However, rather than changing the font color to red, I'm actually trying to bold the wording if the entire detail row if "zz" is in a new column (that has not yet been added to my table).

My goal is to bring attention (with bold text) to items that have been changed or added to the table when the report is created.

Thank you, again,
Peggy
 
When writing code in reports, you need to reference the control names. Table and Field names are not generally significant unless they are the same as the name of the controls.

Duane
Hook'D on Access
MS Access MVP
 
GREAT! I had forgotten that part so now it works for changing the color (as indicated by the original thread).

So, now that I tested the formatting and it worked for changing the color, I tried changing it as follows to bold the title if the number was 162 but it is not working so I know I've done something dumb once again... could you tell me what is incorrect in my statement/code:

Title.FontWeight = IIf((Number) Like "162", Bold, Normal)

Thank you,
Peggy
 
I would change the Like to = and if Number is actually a numeric field then remove the quotes from around 162.
... IIf([Number] = 162 ...

Then search Help on FontWeight and FontBold (I think).

Duane
Hook'D on Access
MS Access MVP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top