Conditional formatting

R

Richard John

I've got a conditional formatting problem in Access 2000. I simply want to
colour any value outside a given range red and the rest green.

Function percentOfYtdTarget(YTDActual As Double, YTDTarget As Double) As
Variant
Dim tmp
tmp = (YTDActual / YTDTarget)
If tmp < 0.95 And tmp > 1.05 Then
percentOfYtdTarget = Format(tmp, "0.0% [Red]")
Else
percentOfYtdTarget = Format(tmp, "0.0% [green]")
End If
End Function

Why doesn't this work?

I expect to give the user the option of selecting the ranges via a form,
later on. I've temporarily hard coded the values for now, for testing
purposes.

I currently set the formatting using the Access Interface (Tools/Conditional
Formatting). But this is unsatisfactory for my requirements. The same rules
apply to several reports so if the rules change it will be a pain to have do
it manually for each report. So I need to change it via a VBA function call.
Trouble is, I've tried some solutions but I can't get any to work. Nowhere
can I find any solutions on line .. MS$ site, Reference books... nothing

Thanks in Anticipation..
 
D

Duane Hookom

I'm not sure about how you are using this but your following line needs to
be changed from:
If tmp < 0.95 And tmp > 1.05 Then
to
If tmp < 0.95 Or tmp > 1.05 Then
 

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