Creating Format Conditions?

P

PeteCresswell

Got a screen that can be put into "Browse" or "Edit" mode.

In "Browse" all fields' .Locked=True and .BackColor=(something besides
white).

In "Edit", .Locked=False and .BackColor=16777215 (which is White)


In "Browse", the fields have conditional formatting that
changes .ForeColor
depending on whether a transaction is a "Buy" (blue) or a
"Sell" (red).

But that conditional formatting seems to prevent setting
the .BackColor to white
when we go into Edit mode.

Consequently, when we go into Edit mode, we blow away the conditional
formatting
before setting .Backcolor.

That works.

But going back into Browse mode, our attempt to re-create the
conditional formatting
seems tb failing.

We're setting the formats, and Debug.Print seems to indicate that
the .ForeColors are
what we want.... but the field is not rendering as expected.

It comes up Black (color #0) in both cases.

Here's the code, followed by what we see in Immediate:
==============================================
9620 Set curForm = Me.subTrades.Form
' --------------------------------------------
' Re-create conditional formatting on trade's "Buy Rate"
' Other fields just have it set via Access UI, but for
BuyRate,
' we have to blow it away when going into edit mode and then
' recreate for browse

9621 With curForm!txtBuyPercent
9629 .FormatConditions.Delete

9630 Set curFC = .FormatConditions.Add(acExpression, , "If
[TradeTypeID]=1")
6631 With .FormatConditions(0)
9632 .ForeColor = gColor_Red_Chinese
9633 .BackColor = mBackColor_PaymentsTrades
9639 End With
Debug.Print "gColor_Red_Chinese='" & gColor_Red_Chinese & "'"
Debug.Print "(0)=" & Forms!frmSecurity!subTrades.Form!
txtBuyPercent.FormatConditions(0).ForeColor

9640 Set curFC = .FormatConditions.Add(acExpression, , "If
[TradeTypeID]=2")
6641 With .FormatConditions(1)
9642 .ForeColor = gColor_Blue_Royal
9643 .BackColor = mBackColor_PaymentsTrades
9649 End With
9660 End With
Debug.Print "gColor_Blue_Royal='" & gColor_Blue_Royal & "'"
Debug.Print "(1)=" & Forms!frmSecurity!subTrades.Form!
txtBuyPercent.FormatConditions(1).ForeColor
==============================================
Immediate:
gColor_Red_Chinese='255
(0)=255
gColor_Blue_Royal='15329769
(1)=15329769
==============================================
 
C

Clifford Bass

Hi Pete,

Either do it all in code or all with conditional formatting. Combining
them is, as you experienced, asking for trouble. My inclination would be to
use code since it is easy to loop through a bunch of controls, setting their
colors and whatnot. No need to set up a ton of similar conditional
formatting definitions. To do it with conditional formatting you can test
for the Locked condition if you use the Expression Is item. Something like:

[txtBuyPercent].Locked and [txtTransactionType] = "Buy"

or something like:

Not [txtBuyPercent].Locked or [txtTransactionType] = "Sell"

You will need to do a Me.Refresh in your browse/edit button's code
after you have changed the locked statuses of the various controls.

Hope that helps,

Clifford Bass

PeteCresswell said:
Got a screen that can be put into "Browse" or "Edit" mode.

In "Browse" all fields' .Locked=True and .BackColor=(something besides
white).

In "Edit", .Locked=False and .BackColor=16777215 (which is White)


In "Browse", the fields have conditional formatting that
changes .ForeColor
depending on whether a transaction is a "Buy" (blue) or a
"Sell" (red).

But that conditional formatting seems to prevent setting
the .BackColor to white
when we go into Edit mode.

Consequently, when we go into Edit mode, we blow away the conditional
formatting
before setting .Backcolor.

That works.

But going back into Browse mode, our attempt to re-create the
conditional formatting
seems tb failing.

We're setting the formats, and Debug.Print seems to indicate that
the .ForeColors are
what we want.... but the field is not rendering as expected.

It comes up Black (color #0) in both cases.

Here's the code, followed by what we see in Immediate:
==============================================
9620 Set curForm = Me.subTrades.Form
' --------------------------------------------
' Re-create conditional formatting on trade's "Buy Rate"
' Other fields just have it set via Access UI, but for
BuyRate,
' we have to blow it away when going into edit mode and then
' recreate for browse

9621 With curForm!txtBuyPercent
9629 .FormatConditions.Delete

9630 Set curFC = .FormatConditions.Add(acExpression, , "If
[TradeTypeID]=1")
6631 With .FormatConditions(0)
9632 .ForeColor = gColor_Red_Chinese
9633 .BackColor = mBackColor_PaymentsTrades
9639 End With
Debug.Print "gColor_Red_Chinese='" & gColor_Red_Chinese & "'"
Debug.Print "(0)=" & Forms!frmSecurity!subTrades.Form!
txtBuyPercent.FormatConditions(0).ForeColor

9640 Set curFC = .FormatConditions.Add(acExpression, , "If
[TradeTypeID]=2")
6641 With .FormatConditions(1)
9642 .ForeColor = gColor_Blue_Royal
9643 .BackColor = mBackColor_PaymentsTrades
9649 End With
9660 End With
Debug.Print "gColor_Blue_Royal='" & gColor_Blue_Royal & "'"
Debug.Print "(1)=" & Forms!frmSecurity!subTrades.Form!
txtBuyPercent.FormatConditions(1).ForeColor
==============================================
Immediate:
gColor_Red_Chinese='255
(0)=255
gColor_Blue_Royal='15329769
(1)=15329769
==============================================
 

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