Results 1 to 5 of 5

Thread: color change erratic in Access

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Posts
    6

    Post

    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

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

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

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Posts
    6

    Post

    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.

  4. #4
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105

    Post

    how about?

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

  5. #5

    Thread Starter
    New Member
    Join Date
    Aug 1999
    Posts
    6

    Post

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width