-
October 19th, 2015, 08:02 AM
#1
Change Backcolor of Textbox when Date is Older Than 7 Days
Hi Everyone
I am new to microsoft visual basic application building. I am busy creating a maintenance inspection application where the user selects a checkbox with a label describing an area. If the checkbox is selected then the date is displayed in a textbox on the same tab. Once the save button is clicked, it copies the date to a "Date Last Inspected" textbox on the same tab as well as to a seperate "Overview" tab with a date last inspected textbox as well. If the form is closed or the save button is clicked the data is "saved"/persisted and it is stored in the application so when the user opens the application he can see when was a particular area last inspected on the "Overview" tab.
I would like to incorporate code that lets all the textboxes on the "Overview" tab that have dates older than 14 days be coloured red, between 14 and 7 days be coloured yellow and less than 7 days be coloured green.
How do I incorporate this into my application? Where must the positioning be each code? I am making use of standard textboxes. Any suggestions and ideas will be greatly appreciated.
Regards
-
October 26th, 2015, 07:49 AM
#2
Re: Change Backcolor of Textbox when Date is Older Than 7 Days
You could use the DateDiff() or the DateAdd() functions to see if the date is within the range you want and then set the color as desired.
As to where you should put the code, that depends on how/when you want to trigger the test and recolor. You may want to do it in whatever routine that loads the data or you may want to do it in a change event or you may want it somewhere else.
Always use [code][/code] tags when posting code.
-
October 26th, 2015, 07:57 AM
#3
Re: Change Backcolor of Textbox when Date is Older Than 7 Days
Thank you for replying DataMister!
Can I use DateAdd and DateDiff even if the date is formatted as a string in the particular textbox? I use [Cstr(Today.Date)].
Regards!
-
October 28th, 2015, 04:38 PM
#4
Re: Change Backcolor of Textbox when Date is Older Than 7 Days
Thank you DataMiser! Works perfectly!!
Regards
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|