Conditional Formatting With Vba

  • Thread starter Thread starter Chipcom
  • Start date Start date
C

Chipcom

I would like to know how to do a conditional formatting with VBA.
I have 3 fields and I need that if the sum of the two fields are
grater than 2.5 then the forecolor of the third field will be red for
example.

Thanks
 
Chip,

You may need to tweak it a little but give it a go with something like this:

dim fcd As FormatCondition
if me.control1 + me.control2 > 2.5 then
with me.control3
with .FormatConditions
.Delete '-remove the old one
set fcd= .Add(acFieldValue, acGreaterThan, 0) '-> tweak this to
your wish
fcd.BackColor= vbRed '-> select the color of your choice
end with
end with
end if
 
Chip,

You may need to tweak it a little but give it a go with something like this:

dim fcd As FormatCondition
if me.control1 + me.control2 > 2.5 then
with me.control3
with .FormatConditions
.Delete '-remove the old one
set fcd= .Add(acFieldValue, acGreaterThan, 0) '-> tweak this to
your wish
fcd.BackColor= vbRed '-> select the color of your choice
end with
end with
end if
--
Maurice Ausum






- Show quoted text -


Hi

I would like to know in which event/function I need to write the code?
What the meaning of the line?:
set fcd= .Add(acFieldValue, acGreaterThan, 0) '-> tweak
this to
your wish

Thanks
 
Chip,

It depends on where you want it to happen. I assume that you could use it
with the On_Exit from the second field.

set fcd= .Add(acFieldValue, acGreaterThan, 0) '-> tweak

Meaning: after the Add( you can set any options you'd like such as: field3,
acGreatherThan, 2.5)

or something like that. Play around with it a little.

hth
 

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

Back
Top