How to change the state of a textbox depending on variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Nick H
    New Member
    • Sep 2010
    • 6

    #1

    How to change the state of a textbox depending on variable

    I hope somebody can help...

    I have a textbox that allows a date to be entered.
    This date is checked with the code below and the background colour is changed if the date is overdue from white, yellow or red (depending on weeks)

    Code:
    Dim DateDifference As Integer
    DateDifference = DateDiff("ww", ApplicationDate, Date)
    
    ApplicationDate.BackColor = Switch(DateDifference >= 7, vbRed, (DateDifference >= 5 And DateDifference < 7), vbYellow, DateDifference < 5, vbWhite, DateDifference = 0, vbWhite)
    This works well but as it is in the AfterUpdate function of the textbox, when the user goes to another record the colour of the textbox remains the same as the previous, until the textbox is edited. I want this to be calculated when a record is displayed AND/OR when it is edited.

    Is there a way of refreshing/requering the code, or putting it somewhere else aswell?

    Thanks
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Nick, use conditional formatting. In design mode, select the text box you want and then on the Formatting menu you will find "Conditiona l Formatting." That will do just what you want.

    Jim

    Comment

    • Nick H
      New Member
      • Sep 2010
      • 6

      #3
      Thank you, can't believe it was that simple!

      Comment

      Working...