Controlling Format Condition in VBA (1 Viewer)

deletedT

Guest
Local time
Today, 20:14
Joined
Feb 2, 2019
Messages
1,218
I'm trying to add a Format Condition to a text box in a form in VBA.
The text Box is OrderedBy

Both following codes are added in form's onOpen event.

If I use the following code, when the form is opened, Format Condition is not applied:
Code:
    With Me.OrderedBy
        .FormatConditions.Delete
        Set fc = .FormatConditions.Add(acFieldValue, acEqual, "Test")
        Set fc = .FormatConditions(0)
        fc.BackColor = 0
        fc.FontBold = True
        fc.ForeColor = 255
    End With


If I change the above code as following, it works:
Code:
    With Me.OrderedBy
        .FormatConditions.Delete
        Set fc = .FormatConditions.Add(acExpression, , "[OrderedBy]='Test'")
        Set fc = .FormatConditions(0)
        fc.BackColor = 0
        fc.FontBold = True
        fc.ForeColor = 255
    End With

Why the first one doesn't work?

Thanks for any kind of advice.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:14
Joined
Oct 29, 2018
Messages
21,474
Hi. Just a guess but have you tried using?
Code:
Set fc = .FormatConditions.Add(acFieldValue, acEqual, "'Test'")
 
Last edited:

deletedT

Guest
Local time
Today, 20:14
Joined
Feb 2, 2019
Messages
1,218
Hi. Just a guess but have you tried using?
Code:
Set fc = .FormatConditions.Add(acFieldValue, acEqual, "'Test'")
Just my 2 cents...

DBguy, You're a genius. Never thought of that.

It's much more than 2 cents.
Million thanks.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 12:14
Joined
Oct 29, 2018
Messages
21,474
DBguy, You're a genius. Never thought of that.

It's much more than 2 cents.
Million thanks.
Hi. Thanks! Glad to hear you got it to work. Good luck with your project.
 

Users who are viewing this thread

Top Bottom