Formatting of Control

khwaja

Registered User.
Local time
Tomorrow, 09:41
Joined
Jun 13, 2003
Messages
254
I used conditional formatting in my continuous form which really works great. So if the field says red, I can paint it red. I initially started writing code to achieve this but does not look like it works well in a continuous form. Anyway, I have a little issue. In terms of field that is subject to formatting, I would additionally like to make it white foregroud and background based on the contents of another field. So for example, if my formatted field says 'red' I would like to change to white font and white background if another field has word "control' in it. I tried the following but it does not quite work on the on current even. Can the code over ride conditional formatting?

Private Sub Form_Current()
If (Me.DesignStatus) = " Control Plan" Then

Me.Stat.ForeColor = vbWhite
Me.Stat.BackColor = vbWhite

Else

Me.Stat.ForeColor = vbBlack
Me.Stat.BackColor = vbWhite

End If

End Sub

Could someone help achieve this?
 
Code solutions don't work well in a form, as you've discovered. Try Conditional Formatting.
 
I have run out of choices for conditional formatting. There is a limit, hence the request.
 
2010 has a higher limit (I think 50, but don't quote me on that). Code works in a report, not really on a form, though if memory serves somebody came up with a workaround. I'll try to find it.
 
Conditional format has three rules so there are only three possible results. However by using the "Expression Is" variant other controls and fields can be incorporated and quite a lot can be achieved with a complex enough expression.
 
Would you be kind enough to explain how to use two criteria as expression? So in my example I wish to test two fields to paint the field.
 
An expression like:

[Field1] = "Whatever" And [Field2] = 123
 
The dropdown where it says "Field Value Is" by default can be changed to "Expression Is"

Then the condition is entered in this style:

Code:
([somefield]>0 AND [anotherfield]=0) OR [yetanotherfield]=2
 
Thanks. Tried the following but then I lost all the formatting. I did leave two other conditions as 'fieldvalueIs' and a simple 'equal to' and the new value.
 
When using the conditions it is important to configure them such that they are unique. For example conditions like [field]>1 and another [field]>2 will both fire on a value of 3. The results is indeterminate.

So you need the two conditions more like this:
[field]>1 AND [field]<=2
[field]>2
 
Thanks. By changing all condition for a similar test actually worked and it works fine. I really would like to thank you for the guidance.

Cheers
 

Users who are viewing this thread

Back
Top Bottom