Results 1 to 11 of 11
  1. #1
    Join Date
    Sep 2008
    Posts
    150

    Unanswered: Adding additional Conditions to Conditional Formatting

    Hello,

    I have a text box that I use to color code milestones based on a value. I use the “Conditional Formatting” tool to format four of the conditions, which works great! Unfortunately, I need an additional two conditions for a total of six.

    I believe the additional two conditions must be created by using code to accomplish what I need, but I do not have a whole lot of knowledge in coding. I am wondering if someone can assist me with creating the last two conditions.

    I need a text box (txtbox_status) to turn “Green” when I enter the number “5” in the text box and “Pink” when I enter the number 6.

    Appreciate any help I can get. Thanks.

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Is it a continuous form?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Sep 2008
    Posts
    150
    No, it is a Single Form.

  4. #4
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Good, then you can do it with code.

    After Update for the box in question (and a call to it in the form's On Current).

    Code:
    If Me.txtbox_status = 5 Then
       Me.txtbox_status.BackColor = vbGreen 
    ElseIf Me.txtbox_status = 6 Then
       Me.txtbox_status.BackColor = vbPink    'probably need a colour number here 
    Else
       Me.txtbox_status.BackColor = vbWhite
    Endif
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  5. #5
    Join Date
    Sep 2008
    Posts
    150
    Hello StarTrekker,

    Thank you for providing me assistance with my conditional formatting issue.

    I added the following code to the "On Current" event on the form, but the code is not working. What am I doing wrong?

    <CODE>
    Private Sub Status_AfterUpdate()

    If Me.TxtBox_Status = 5 Then
    Me.TxtBox_Status.BackColor = RGB(204, 255, 204)
    ElseIf Me.TxtBox_Status = 6 Then
    Me.TxtBox_Status.BackColor = RGB(255, 153, 204) 'probably need a colour number here
    Else
    Me.TxtBox_Status.BackColor = RGB(255, 255, 255)
    End If

    End Sub


    Private Sub Form_Current()

    Me.TxtBox_Status.BackColor = RGB(204, 255, 204)
    Me.TxtBox_Status.BackColor = RGB(255, 153, 204)
    Me.TxtBox_Status.BackColor = RGB(255, 255, 255)

    End Sub
    <CODE>

  6. #6
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    try a me.repaint command (to "repaint" the screen) after the End If in the Status_AfterUpdate() (or Form_Current before the End Sub).
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  7. #7
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    No no, you call the code from OnCurrent:

    Code:
    Private Sub Status_AfterUpdate()
       If Me.TxtBox_Status = 5 Then
          Me.TxtBox_Status.BackColor = RGB(204, 255, 204)
       ElseIf Me.TxtBox_Status = 6 Then
          Me.TxtBox_Status.BackColor = RGB(255, 153, 204) 'probably need a colour number here
       Else
          Me.TxtBox_Status.BackColor = RGB(255, 255, 255)
       End If
    End Sub
    
    
    Private Sub Form_Current()
       Call Status_AfterUpdate
    End Sub
    No repainting should be necessary.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  8. #8
    Join Date
    Dec 2004
    Location
    Madison, WI
    Posts
    3,926
    Quote Originally Posted by StarTrekker
    No repainting should be necessary.
    True - but I use it in those odd situations where the code doesn't change the colors for some reason.

    In those unique situations....("Microsoft Access sometimes waits to complete pending screen updates until it finishes other tasks. With the Repaint method, you can force immediate repainting of the controls on the specified form.") - noting the wording "sometimes" used in the MSAccess help quote.

    If I know the code "should" change the colors but it doesn't, adding a me.repaint command usually solves the issue but you are correct that it should not usually be necessary.
    Last edited by pkstormy; 10-11-08 at 10:46.
    Expert Database Programming
    MSAccess since 1.0, SQL Server since 6.5, Visual Basic (5.0, 6.0)

  9. #9
    Join Date
    Sep 2008
    Posts
    150
    It Works!!

  10. #10
    Join Date
    Sep 2008
    Posts
    150
    It Works!!

    Thanks to the both of you for assisting me with this color issue.

  11. #11
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    You're most welcome
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

Posting Permissions

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