• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How can I change TextBox BackColor based on actual date?

Hello. I'd love to get help to make a Textbox to change the back color based on the actual date. I have set 12 Textboxes, but I need the Textboxes to change the back color depending on the actual date. For example. If today is January 1st, I need the Textbox to change the back color to "Red", but if today is December 31st, I need the Textbox to change the back color to "Gray" Another example: In the file that I have sent as an attachment, Textbox5(which represents "May", the Textbox called "txDate" displays the actual date " Tuesday, May 25, 2021". I need that the Textbox5 to change color to red(May has 31 days, so Textbox5 represents all the month of May), and after May 31st, I need that Textbox5 to change the back color to "Gray" and when the actual date changes to June 1st, Textbox6 will automatically to change back color to "Red" and so on forth. It´s like highlighting the Textbox that matches the "Actual Date" criteria and when the month changes, to turn back the Textbox to another color the Textbox that doesn't match. I hope to have explained in an assertive way what I need. I the pictures I have sent, you can see an example of what I need.

Thank you so much in advance.
 

Attachments

  • May.JPG
    May.JPG
    28 KB · Views: 8
  • June.JPG
    June.JPG
    35.2 KB · Views: 6
  • Test.xlsm
    13.5 KB · Views: 7
>>> use code - tags <<<
Code:
txtMonth = Format(Date, "mm")
For Each ct In F_00.Controls
    ct.BackColor = vbWhite
Next ct
For Each ct In F_00.Controls
    If ct.Tag = txtMonth Then ct.BackColor = RGB(255, 0, 0)
    If ct.Tag < txtMonth Then ct.BackColor = RGB(192, 192, 192)
Next ct
question...when you say "For each ct In F_00.Controls"...What does "ct" mean?
 
Last edited by a moderator:
ct is short for control, that I use,you can use whatever word you want.
F_00 is the name i gave to the frame where I put the textboxes in, So the code only applies to the controls that are in that frame.
 
Back
Top