Conditional formatting

  • Thread starter Thread starter NevilleT
  • Start date Start date
N

NevilleT

I am trying to get conditional formatting to work using VBA. The formatting
is on a subform and I want to change the colour of a text box (txtTaskName)
if a checkbox called chkSummary is true.

When I open the form, there is no format change. If I move my mouse over
the column, as I move over each record it turns blue even if the condition is
true or not.

Dim objFormCon As FormatCondition
Dim lngBlue As Long

lngBlue = RGB(139, 219, 233)

'Remove existing format conditions
Me!txtTaskName.FormatConditions.Delete

Set objFormCon = Me![txtTaskName].FormatConditions.Add(acExpression, _
, Me.chkSummary = True)

With Me!txtTaskName.FormatConditions(0)
.ForeColor = lngBlue
End With
 
NevilleT said:
I am trying to get conditional formatting to work using VBA. The formatting
is on a subform and I want to change the colour of a text box (txtTaskName)
if a checkbox called chkSummary is true.

When I open the form, there is no format change. If I move my mouse over
the column, as I move over each record it turns blue even if the condition is
true or not.

Dim objFormCon As FormatCondition
Dim lngBlue As Long

lngBlue = RGB(139, 219, 233)

'Remove existing format conditions
Me!txtTaskName.FormatConditions.Delete

Set objFormCon = Me![txtTaskName].FormatConditions.Add(acExpression, _
, Me.chkSummary = True)

With Me!txtTaskName.FormatConditions(0)
.ForeColor = lngBlue
End With


The expression is a string argument:

... , "[chkSummary] = True")

I don't understand why, but the [ ] seem to be required.
 
Thanks Marsh. Worked perfectly. Sometimes common sense just gets you into
trouble. Never considered it would be a string.

Marshall Barton said:
NevilleT said:
I am trying to get conditional formatting to work using VBA. The formatting
is on a subform and I want to change the colour of a text box (txtTaskName)
if a checkbox called chkSummary is true.

When I open the form, there is no format change. If I move my mouse over
the column, as I move over each record it turns blue even if the condition is
true or not.

Dim objFormCon As FormatCondition
Dim lngBlue As Long

lngBlue = RGB(139, 219, 233)

'Remove existing format conditions
Me!txtTaskName.FormatConditions.Delete

Set objFormCon = Me![txtTaskName].FormatConditions.Add(acExpression, _
, Me.chkSummary = True)

With Me!txtTaskName.FormatConditions(0)
.ForeColor = lngBlue
End With


The expression is a string argument:

... , "[chkSummary] = True")

I don't understand why, but the [ ] seem to be required.
 
Back
Top