Highlight field based on condition. Please help!

ktran4

New member
Local time
Today, 13:02
Joined
Feb 27, 2016
Messages
8
Hello,

I need to highlight [DueDT] when it is due 10 days from today and part has not received in [ReceiveDT] when form is open.

Can someone help me with the code please? Your help is appreciated.

Warm regards,
Ktran4
 
Use ConditionalFormating. (Right click on the textbox.)
 
If you want to do this with a more complex computation, you can also do this in the form's Form_Current routine, by checking the condition and deciding whether to set the colors with black and white, or with yellow and red, or some other color scheme.

In the _Current routine,

Code:
    IF DateDiff( "d", Now(), [DueDt] ) < 10 THEN
        [DueDt].ForeColor = vbRed
    ELSE
        [DueDt].ForeColor = vbBlack
    END IF

You could also do things with .BackColor and .BorderColor if you wanted. You might have to look up how to "roll your own color" with, say, the RGB function or something like that, if you don't want the "pure" colors. But heck, play with it. Also, I always get the order wrong on DateDiff, but it THINK I got that in the right order this time.
 
If you want to do this with a more complex computation, you can also do this in the form's Form_Current routine,

Code:
    IF DateDiff( "d", Now(), [DueDt] ) < 10 THEN
        [DueDt].ForeColor = vbRed
    ELSE
        [DueDt].ForeColor = vbBlack
    END IF

Perhaps not the best example. That is just a more complex way to do what can also be done with ConditionalFormatting.

Although ConditionalFormatting is limited to changing ForeColor and BackColor, it can also conditionally Enable a textbox, which is a really useful ability.

The big advantage of ConditionalFormatting is that it works on ContinuousForms, something that code based techniques cannot manage.
 
Thank so much for your help, Galaxiom and The Doc Man!:)
I tried the conditional format and also the current event.
But it is not exactly what I want.

The highlight only happens when the [ReceivedDT] is null. If the [ReceivedDT] is entered, then no change.

I like to use the conditional format on a continuous form. What can I put in the expression to achieve this result? Your help is greatly appreciated.

Warm regards,
Ktran4
 
click on DueDT control on the form and use conditional format (on expression):

Expression Is: IsNull([ReceivedDT])
 
you can do it by using conditional formatting. it is quite simple. n the Conditional formatting dialog, select Cell Value Is in the first drop-down box.
Select a cell evaluator from the second drop down box. Your dialog may change and add another field.
Enter your values in the remaining text boxes.
Click the Format… button.
Choose your format options from the Font, Border and Patterns tabs.
Click OK.
Click OK or add another condition
 
In the Conditional formatting dialog, select Cell Value Is in the first drop-down box.

Not quite Katie.

They need to use the Expression Is rule to refer to values in a different field.
 
[Solve] Highlight field based on condition. Please help!

It works! I can't express enough how much I appreciate everyone for your help!:)

Best regards,

Ktran
 

Users who are viewing this thread

Back
Top Bottom