Conditional formatting

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
 
M

Marshall Barton

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.
 
N

NevilleT

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.
 

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