Conditional Formatting Error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tulikapuri
    New Member
    • Feb 2007
    • 55

    Conditional Formatting Error

    I am trying to add more than three conditional formatting conditions such that
    If the Moisture values is > 3.5 it turns the text box = Red
    is between 2.35 - 3.25 , the text box = Green
    is > 3.25 and < 3.5 = Yellow
    is < 2.35 and >2.10 = Yellow
    is < 2.10 = Red
    How can i write a Code for the same ?

    I tried this code but it asks me for the text range, can someone help me resolve this issue please ?

    Code:
    Select Case Me![txtRange]
      Case Is > 3.5
         Me![txtMoisture Values].ForeColor = vbRed
      Case 2.35 To 3.5
         Me![txtMoisture Values].ForeColor = vbGreen
      Case 2.10 To 2.34
         Me![txtMoisture Values].ForeColor = vbYellow
      Case Is < 2.1
         Me![txtMoisture Values].ForeColor = vbRed
      Case Else
         Me![txtMoisture Values].ForeColor = vbBlack
    End Select
    Last edited by NeoPa; Jun 2 '07, 02:24 PM. Reason: Tags
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Originally posted by tulikapuri
    I am trying to add more than three conditional formatting conditions such that
    If the Moisture values is > 3.5 it turns the text box = Red
    is between 2.35 - 3.25 , the text box = Green
    is > 3.25 and < 3.5 = Yellow
    is < 2.35 and >2.10 = Yellow
    is < 2.10 = Red
    How can i write a Code for the same ?

    I tried this code but it asks me for the text range, can someone help me resolve this issue please ?

    Select Case Me![txtRange]
    Case Is > 3.5
    Me![txtMoisture Values].ForeColor = vbRed
    Case 2.35 To 3.5
    Me![txtMoisture Values].ForeColor = vbGreen
    Case 2.10 To 2.34
    Me![txtMoisture Values].ForeColor = vbYellow
    Case Is < 2.1
    Me![txtMoisture Values].ForeColor = vbRed
    Case Else
    Me![txtMoisture Values].ForeColor = vbBlack
    End Select
    Why not just use the conditional formatting wizard?

    [txtRange] should be [txtMoistureValu es]

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by tulikapuri
      I am trying to add more than three conditional formatting conditions such that
      If the Moisture values is > 3.5 it turns the text box = Red
      is between 2.35 - 3.25 , the text box = Green
      is > 3.25 and < 3.5 = Yellow
      is < 2.35 and >2.10 = Yellow
      is < 2.10 = Red
      How can i write a Code for the same ?

      I tried this code but it asks me for the text range, can someone help me resolve this issue please ?

      Select Case Me![txtRange]
      Case Is > 3.5
      Me![txtMoisture Values].ForeColor = vbRed
      Case 2.35 To 3.5
      Me![txtMoisture Values].ForeColor = vbGreen
      Case 2.10 To 2.34
      Me![txtMoisture Values].ForeColor = vbYellow
      Case Is < 2.1
      Me![txtMoisture Values].ForeColor = vbRed
      Case Else
      Me![txtMoisture Values].ForeColor = vbBlack
      End Select
      As previously stated on several occassions, [txtRange] and [txtMoisture Values] are Field names that I used solely for demonstration purposes. You must substitute your own Field Names.

      Comment

      • Cosmos75
        New Member
        • May 2007
        • 1

        #4
        'Conditional Formatting' of controls in a continuous form

        Hope that helps!

        Comment

        • puppydogbuddy
          Recognized Expert Top Contributor
          • May 2007
          • 1923

          #5
          I've had this problem before. If I remember correctly the value in the textboxes have to be converted to Double precision using CDbl before the Select case can deal wiith them as decimal fractions.

          Code:
          Me![txtRange].Value = CDbl(Me![txtRange])
          Me![txtMoistureLevels].Value = CDbl(Me![txtMoistureLevels])
           
          Select Case Me![txtRange]
          -----------

          It might be worth a try here.
          Last edited by NeoPa; Jun 2 '07, 02:23 PM. Reason: [CODE] Tags !!!

          Comment

          • ADezii
            Recognized Expert Expert
            • Apr 2006
            • 8834

            #6
            Originally posted by puppydogbuddy
            I've had this problem before. If I remember correctly the value in the textboxes have to be converted to Double precision using CDbl before the Select case can deal wiith them as decimal fractions.

            Me![txtRange].Value = CDbl(Me![txtRange])
            Me![txtMoistureLeve ls].Value = CDbl(Me![txtMoistureLeve ls])

            Select Case Me![txtRange]
            -----------

            It might be worth a try here.
            We initially went over this ground where Moisture Values and Range were stored internally as SINGLE Precision Numbers. The Text Boxes referring to these Fields should return Variants of SubType SINGLE which should not pose any problem with the Select Case Statement. It is a very good point that definately should be double checked.

            Comment

            Working...