Conditional Formatting: Change .BackColor on-the-fly?

P

PeteCresswell

I've got some fields whose .BackColor gets changed by code.

But they also have conditional formatting on them.

For instance, if the trade type = Buy, .ForeColor=Blue, but if trade
type = Sell, .ForeColor=Red.

Problem is that the conditional formatting seems to also
specify .BackColor.

I can set the .BackColor in the conditional formatting dialog, but the
next time the code changes .BackColor of all the fields, it their
new .BackColor will get trumped by the conditional formatting.

Seems like I need to get into each field's conditional formatting when
I set .BackColor and change it.

Anybody know what the props/collection/whatever is/are that I should
be going after?
 
F

fredg

I've got some fields whose .BackColor gets changed by code.

But they also have conditional formatting on them.

For instance, if the trade type = Buy, .ForeColor=Blue, but if trade
type = Sell, .ForeColor=Red.

Problem is that the conditional formatting seems to also
specify .BackColor.

I can set the .BackColor in the conditional formatting dialog, but the
next time the code changes .BackColor of all the fields, it their
new .BackColor will get trumped by the conditional formatting.

Seems like I need to get into each field's conditional formatting when
I set .BackColor and change it.

Anybody know what the props/collection/whatever is/are that I should
be going after?

Take a look at VBA help on
FormatConditions Collection
and
FormatCondition Object
and
Modify Method
 
P

PeteCresswell

Take a look at VBA help on
FormatConditions Collection
and
FormatCondition Object
and
Modify Method

That was the ticket. FWIW, here's what I came up with.
Seems to work.....
================================================================
Public Sub ControlSet_BackColor(ByVal theBackColor As Long, ByRef
theControl As Control)
4000 debugStackPush mModuleName & ": ControlSet_BackColor"
4001 On Error GoTo ControlSet_BackColor_err

' PURPOSE: To unconditionally set a control's .BackColor
' ACCEPTS: Pointer to control in question

4002 Dim i As Long
Dim k As Long

Dim curName As String
Dim curLeft As String

4011 curName = theControl.Name
4012 curLeft = Left(curName, 3)

4020 If ((curLeft <> "chk") And _
(curLeft <> "cmd") And _
(curLeft <> "lin") And _
(curLeft <> "rct") And _
(curLeft <> "sub")) Then
4029 theControl.BackColor = theBackColor

4030 If curLeft = "txt" Then
4031 k = theControl.FormatConditions.Count
4032 If k > 0 Then
4033 For i = 0 To k - 1
4034 theControl.FormatConditions(i).BackColor =
theBackColor
4035 Next i
4036 End If
4039 End If
4999 End If

ControlSet_BackColor_xit:
DebugStackPop
On Error Resume Next
Exit Sub

ControlSet_BackColor_err:
BugAlert True, "Control name = '" & curName & "'."
Resume ControlSet_BackColor_xit
End Sub
================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top