Bold and Color

kitty77

Registered User.
Local time
Today, 05:27
Joined
May 27, 2019
Messages
715
How do I make a font both bold and a color?

[sample].FontBold = True And [sample].ForeColor = vbBlue
 
Textbox property is FontWeight, not FontBold.
 
Ok, changed it to FontWeight but I can't seem to get it to be bold and color. Only works, one or the other.

[sample].FontWeight =700 (works)
[sample].ForeColor = vbBlue (works)

But not together?
 
Okay, correction - VBA does show FontBold even though it does not show on Properties Sheet.

Code works for me, with either FontWeight or FontBold and ForeColor. All properties are set.
 
Does not work for me?
If [sample] < 400 Or [sample] > 500 Then [sample].ForeColor = 858083 And [sample].FontWeight = 800

The font just remains black and not bold when I put them together.
 
you should try to "test" the "content" of the textbox and not it's color or anything.
color can be set when a certain "condition" occurs.
use conditional format.
 
Yes but I have it on a command button that is doing some calculations too.
 
I think the conditional formatting might actually work better.
 
Well, you can't do " AND ". Needs to be multi-line with If Then End If.

And if you want the settings to be dependent on a value and form is in Continuous or Datasheet, then have to use Conditional Formatting.

Otherwise, need code in control AfterUpdate as well as form Current. And you need to specify settings for when value is outside criteria.
 
Last edited:
If [sample] < 400 Or [sample] > 500 Then [sample].ForeColor = 858083 And [sample].FontWeight = 800

This is valid syntax but not valid semantics. Your actual expression compiles but here is what it actually says:

If (your conditions are met) THEN [sample].Forecolor = ( 858083 AND ( [sample].FontWeight = 800 )
... which is to say set the forecolor to the logical (bitwise) AND of the bits of number 858083 and the bits of the truth value of the relational expression FontWeight = 800. FontWeight either IS or IS NOT equal to 800, so the sub-expression is either TRUE or FALSE. Therefore ... 858083 AND TRUE will equal 858083, whereas 858083 AND FALSE will equal 0, which is the same as Forecolor = vbBlack.

The correct way to implement changes to TWO properties of a single control follows the example below.

Code:
IF ....conditions THEN
    control.property1 = value1     'pick the correct property, of course
    control.property2 = value2     'individually set the selected property
END IF
 
I may be wrong, but I think I had a problem like this, and it's possible that some themes will ignore these settings. I can't remember the resolution.
 

Users who are viewing this thread

Back
Top Bottom