View Full Version : Question: Want to color dates


grifter6
08-18-2008, 11:18 AM
I need a String that will use the date and time from the cpu to tell me whether or not a training course is outdated by coloring the good dates in green and the out of dates in red. Training courses are annual.
Any Help would be greatly appreciated.

pbaldy
08-18-2008, 11:21 AM
The simplest tool would be Format/Conditional Formatting in a form or report, comparing your field against the built-in function Now(), which returns the current date/time.

grifter6
08-18-2008, 12:58 PM
Any Way you could give a little walk through?

CyberLynx
08-18-2008, 01:24 PM
- In Design View....select the Form Control you would like to apply Conditional Formating to.
- In the MS-Access Menu Bar at the top select: Format and then Conditional Formating...

- For Condition 1 select:
- - - Field Value is
- - - In the Condition Combo select Less Than
- - - In the Condition Text Box enter Now()
- - - Select Red For the Text Color.

- Select the Add button located at the bottom of the Format Conditions dialog box;

- For Condition 2 select:
- - - Field Value is
- - - In the Condition Combo select greater than or equal to
- - - In the Condition Text Box enter Now()
- - - Select Green For the Text Color.

Select the OK Button. Done.

.

grifter6
08-20-2008, 10:05 AM
Thanks for the advice but it did not work I need Access to recognize If a date is good up to a year, for example if I had taken an annual training course on Aug 18 2007, It would be outdated 2 days ago and the text of the date should turn red, and another course I had taken on Aug 22 2007 would still be green because it is still within annual qualifications. If any one can give me a hint that would be great, also I am dealing with over two hundred employees who take these courses at different times throughout the year and having to set the conditional formatting to a static date would be not to efficient. If someone would like to see an example of what im working with here I could post one if that would help.

grifter6
08-20-2008, 10:08 AM
Also, Could using the calendar control in my form help solve this in any way?

CyberLynx
08-20-2008, 12:47 PM
The Calender Control would is used for displaying a calendar and for selecting Dates from that Calender. It will not help you with this particular situation.

Conditional Formating is still the easiest way to go here. It's all a matter of applying the proper evaluation string for the Condition to take place.

It still isn't really clear as to when the actual Course Qualification has expired. Is it exactly one year to the day or is it one year less a day? For example:

One Year to the Day:
Still Qualifies: August 18, 2007 to August 18, 2009
Does Not Qualify: August 18, 2007 to August 19, 2009

One Year Less A Day:
Still Qualifies: August 18, 2007 to August 17, 2009
Does Not Qualify: August 18, 2007 to August 18, 2009

If any case, I'll provide for both here and you can pick whichever evaluation string that best suits your needs. Let's redo the Conditional Formating for your Form Text Box and, for the sake of this example, let's call this Text Box Text1:

- Place the Form into Design View and select the Text1 Text Box;
- Now Open the Conditional Formating Dialog window. In the MS-Access Menu Bar at the top select: Format and then Conditional Formating...;
- For the Default Condition...set the Text Color to Green. That's all.
- In Condition 1...Set the Condition Type to Expression Is
- Copy and Paste either one of the following Expressions:

For "One Year to the Day": DateAdd("yyyy",1,CDate([Text1])) < Format(Now(),"Short Date")

OR

For "One Year Less a Day": DateAdd("yyyy",1,CDate([Text1])) <= Format(Now(),"Short Date")

- Set the Character Color for this Condition to Red;
- Now, select the OK button located at the bottom of the Conditional Formating dialog window;
- Done.

Be sure you remembered to change the Text1 name to the name you have used for the Text Box on your Form.

That should take care of things.

.

grifter6
08-21-2008, 10:20 AM
Here is a sample of what im trying to do. I was trying to use text instead of date and time, Because not all training is needed by every employee so I put NR or Req. depending on the needs of the employee, If I use time and date I can't use any text. So unless we can make not required fields hold for instance, 1/11/1111, and make the text blue, to indicate required fields as Yellow 2/22/2222, maybe, but only if there is no way to indicate the courses validity in the text format. Additionally the string Cyberlynx posted only works if the date is in the current month, so 5/15/2008 shows up as an invalid date, even though it is well within the year to date time limit.

I do appreciate the help though, I am closer to getting it to work than before, that is why I posted the sample so maybe you can have a better Idea of what im trying to accomplish.

grifter6
08-21-2008, 10:23 AM
this is it

CyberLynx
08-22-2008, 02:33 AM
Before modifications can be made...

- What is the LO/TO field for?
- Does the LO/TO field need to change colors as well?
- Are all three of the last fields in the Form to change color depending upon a specific condition?
- Are these last three fields to be based from the LO/TO Field or the Current (todays) date?

What you want to do can be easily done....you're just not giving enough specifics of what you want.

The DateDiff Strings I provided in my last post should work based on a specific Date to the Current date. For example:

If the specific Date was April 12, 2007 and the Current date was April 13, 2008 (one year + a day) then the text would be Red. It the Current Date was November 2, 2007 or March 12, 2008 or April 1, 2008 or April 12, 2008 then the text would be green. These are all less than a year expired.

.

CyberLynx
08-22-2008, 03:45 AM
In any case....here is your Sample DB back to you with Conditional Formating on the Fields I think it is you want.

Please let me know if it's not what you were looking for.

.

grifter6
08-22-2008, 09:54 PM
You are the man cyberlynx, I really appreciate it dude.