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

  • Follow


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?
0
Reply PeteCresswell 3/14/2008 3:55:53 PM

On Fri, 14 Mar 2008 08:55:53 -0700 (PDT), PeteCresswell wrote:

> 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

-- 
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
0
Reply fredg 3/14/2008 5:50:50 PM


> 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
================================================================
0
Reply PeteCresswell 3/18/2008 9:01:07 PM

2 Replies
606 Views

(page loaded in 0.044 seconds)

Similiar Articles:
















7/25/2012 12:31:47 AM


Reply: