-
I have a calculated txtbox that figures percent from 2 other fields in an Access report. I have an event procedure in the ON FORMAT property to change the color of text to red if it is over 5.0%. This is the event procedure:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Me![Percent].ForeColor = IIf(Me![Percent] >= "5.0", 255, 0)
End Sub
This is producing erratic results. 0.6%, 1.0%, 8.2%, 0.7%, etc. The format is percent and decimal place is 1. Can someone tell me where I am going wrong. Appreciate any help I can get.
Traci
-
I suspect that the percent value is stored without formatting and you're checking a formatted string "5.0" to a non-formatted string "6" for the .6% example. Perhaps if you removed the "." to make your comparison "50".
I could be wrong...
-
I tryed using 50 but it didn't do the trick.
I also tryed using the same code on a field that was just number (no percent) and got the same erratic results. Please help.
-
how about?
Me![Percent].ForeColor = IIf(CDbl(Me![Percent])) >= 5.0, 255, 0)
-
Finally got it if anyone is interested.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
If [Percent] >= 0.05 Then
[Percent].ForeColor = 255
Else
[Percent].ForeColor = 0
End If
End Sub
I guess Access doesn't like IIF here.