Use "Like" function in conditional formatting on form.

  • Thread starter Thread starter Daveo
  • Start date Start date
D

Daveo

Hi folks,

Is it possible to use the "Like" function in an expression for a
conditional formatting rule.

e.g.
Like "*" & [Forms]![myform].[myfield] & "*"

I have a field that always contains either value X or value Y but has
additional information concatenated onto it that changes, and I would
like the field to be blue for value X and green for value Y.

Thanks - David
 
Hello David.

Daveo said:
Is it possible to use the "Like" function in an expression
for a conditional formatting rule.
e.g.
Like "*" & [Forms]![myform].[myfield] & "*"

I have a field that always contains either value X or value Y but has
additional information concatenated onto it that changes, and I would
like the field to be blue for value X and green for value Y.

Should be possible, using "expression is" and an expression like:
[myfield] Like "*X*"
 
Hi David,

I don't think you need the Like function to change the format, you need to
determine the value in the field and then change the color accordingly. I
hope this is what your looking for.

Private Sub Form_Current()

If Left(Me.txtField, 1) = "x" Then
Me.txtField.ForeColor = RGB(0, 0, 255)
ElseIf Left(Me.txtField, 1) = "y" Then
Me.txtField.ForeColor = RGB(0, 255, 0)
Else
Me.txtField.ForeColor = RGB(0, 0, 0)
End If

End Sub

Note that:
- You need to replace [txtField] with your own field's name;
- The text color is changed with this, to change the background color you
need to use BackColor;
- You can also put this code in the in the AfterUpdate event of your text
field.

Good luck,
Philo

Hi folks,

Is it possible to use the "Like" function in an expression for a
conditional formatting rule.

e.g.
Like "*" & [Forms]![myform].[myfield] & "*"

I have a field that always contains either value X or value Y but has
additional information concatenated onto it that changes, and I would
like the field to be blue for value X and green for value Y.

Thanks - David
 
Wolfgang - I can't seem to get the syntax right. I'm entering
[txtSatStatus] = Like "*Coen*" and get an invalid syntax error.

Philo - I'll probably go for your option, but need to use the Like
function or similar. E.g. The field may contain "Project X - Coen" or
"Coen - XXXXXX" and I need the field to go a certain colour if any part
of it contains the work "Coen". Could you show me how to modify your
code to do that please?

Thanks for the help - David
 
Back
Top