PDA

Click to See Complete Forum and Search --> : color change erratic in Access


Traci Thomason
Aug 17th, 1999, 05:29 PM
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

JHausmann
Aug 18th, 1999, 04:46 AM
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...

Traci Thomason
Aug 18th, 1999, 05:46 PM
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.

JHausmann
Aug 19th, 1999, 11:45 AM
how about?

Me![Percent].ForeColor = IIf(CDbl(Me![Percent])) >= 5.0, 255, 0)

Traci Thomason
Aug 19th, 1999, 05:09 PM
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.