Using DateDiff in Access to colour code dates in Conditional Formatting - ms-access

I have a table of clearances and their expiry dates. If a clearance has expired I would like it to be red, if it expires within 6 months I want it to be amber, if it expires in more than 6 months green and if it is yet to be granted (hence doesn't yet have an expiry date) then black.
I have got the text to default as black and then have
RED
[C_ExpiryDate]<Now()
AMBER
DateDiff("m",[C_ExpiryDate],Now())<6 And [C_ExpiryDate]>Now()
GREEN
DateDiff("m",[C_ExpiryDate],Now())>6 And [C_ExpiryDate]>Now()
This seems to have a few different problems, the red works fine from what I can tell. But the other two seem to be handled poorly, for example a clearance with 06 Sep 2015 is amber (today is 03 July 2014 so this should be green). Similar for 05 Mar 2017, I think it is just looking at the month regardless of the year, but I'm not too sure how to handle this better.
Not sure if it might be easier to default as green and perhaps write something like
[C_ExpiryDate] = ""
But this didn't seem to do anything and everything was coming up as green even when there was a blank date. Similar for single quotations.
Any suggestions appreciated...

Which version of MS Access are you using? This works for me:

The way you have it written this is happening (i'm substituting #06/Sept/2015# for [C_ExpiryDate] to keep with your example)
Red?
#06/Sept/2015#<Now() --> False
Amber?
DateDiff("m",#06/Sept/2015#,Now())<6 And #06/Sept/2015#>Now() --> True
Green is not evaluated
The problem is that you have the greater date first and the lesser date last. Switch them.
Or alternatively, since you are checking [C_ExpiryDate]>Now() anyway you can take the absolute value of them and not worry about order.
#06/Sept/2015# < Now() --> False (Red)
DateDiff("m",Now(),#06/Sept/2015#) < 6 And #06/Sept/2015# > Now() --> False (Amber)
DateDiff("m",Now(),#06/Sept/2015#) > 6 And #06/Sept/2015# > Now() --> True (Green)
You have no equal to 6 months condition though. Something for you to think about.

Related

expression to change the fill colour of textbox if the date is greater or equal to 7 days before the expected end date column

i have a report that shows a tenancies expected end date in the last column and a textbox in the column to the left that uses the expression =DateAdd("d", -7, Fields!exp_tncy_end.value) to show the date 7 days before the expected end date so if the expected end date was 13/09/20 then textbox21 would display 6/9/20
many of these expected end dates are way in the future
what i would like to happen is that as we approach the week that the exp_tncy_end date is due i would like the date in textbox21 to change to red, see circled example below
example of report
can anyone help with an expression that would achieve this?
regards
Kieran
Set the color property in the textbox you want to change to this...
=IIF(DateDiff(DateInterval.Day, Today(), Fields!exp_tncy_end.Value) <=7, "Red", "Black")
Note that this will calculate the based on the day number, not a 24 hour period so you might want to adjust the number of days you check for to suit your specific needs.

How can I create a date field by HTML5 Pattern (DD.MM.YYYY)

I have that code:
(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))
Checks that
1) the year is numeric and starts with 19 or 20,
2) the month is numeric and between 01-12, and
3) the day is numeric between 01-29, or
b) 30 if the month value is anything other than 02, or
c) 31 if the month value is one of 01,03,05,07,08,10, or 12
It's from page http://html5pattern.com/Dates
I tried to move some part of code, but then this code doesnt work... Even I tried to find some instructions how can I do it. But I can't handle with it...
How can I get a result like with above code but in format:
DD.MM.YYYY
Also is there any possibility to add the dots in field that user can only input the numbers without dots?
(I mean that the dots will be there every time)
Thank you for help.
Sorry for my English.
I think this is something that you are looking for:
(?:(?:0[1-9]|1[0-9]|2[0-9])\.(?:0[1-9]|1[0-2])|(?:30)\.(?:(?!02)(?:0[1-9]|1[0-2]))|(?:31)\.(?:0[13578]|1[02]))\.(?:19|20)[0-9]{2}
Also tried some possible test cases and worked fine:
You can use an input mask plugin for some of what you are asking for instead I suppose.
One popular one that comes to my mind is Robin Herbots: https://github.com/RobinHerbots/Inputmask
You can find demos off his page here: https://robinherbots.github.io/Inputmask/index.html
Once you implement the plugin into your page, then it's just a matter of establishing the right input tags and jquery for them. For example:
Your phone number script would then be something along the lines of:
<script type="text/javascript">
$("#Phone").inputmask({mask: "999.999.9999"});
</script>
You should look up the documentation for it.

Creating a Report in SSRS

I am attempting to create a report to change Values to Red, Yellow and Green based upon the last inspection date. Inspections are every three years if DUE is in the last inspection then I want the cell to turn red, if the last inspection has been in the last 2 years I need it green and in the year that it needs and inspection I need it yellow.
Here is what I have NOT working :)
=SWITCH(Fields!Inspection_x0020_Expires0.Value = "DUE","Red"),
(Fields!Last_Inspection.Value = "d" < 730,"Yellow")
(Fields!Last_Inspection.Value = "d" > 730,"Green")
Thank you for taking the time to help me.
Tim
Use the DATEDIFF function to compare the last inspection date to today.
DateDiff(DateInterval.Day, Fields!Last_Inspection.Value, Today) < 730
Here is what I ended up doing, I added a column Named Textbox6 and calculated the number of days with a DateDiff =DateDiff("d", Fields!Inspection_x0020_Expires0.Value, Today()) to get the number of days and then I used that value to create my background text box color
=Switch (Not(isNothing(Fields!Last_Inspection.Value)) and ReportItems!Textbox6.Value <= 729, "Green", ReportItems!Textbox6.Value >= 730 and ReportItems!Textbox6.Value <=1094 , "Yellow", isNothing(Fields!Last_Inspection.Value) or ReportItems!Textbox6.Value>1094, "Red" )

f.date_select: display month and year together in one single option menu?

Instead of separate option menus (one for year and one for month), how could I merge year and month into visually one single menu for a date attribute?
Each option would be a year/month pair, i.e.
2014 January
2014 February
Currently I have this code: f.date_select :begin_date, discard_day: true (to visually exclude the days).
You might like the following small jQueryUI code, which does exactly what you describe: http://lucianocosta.info/jquery.mtz.monthpicker/

SSRS 2008 R2 Charts - Hide WhiteSpace for a series value that returns 0

I need to remove the whitespace for the bars (or series) that do not return a value.
The chart I posted returns no values for April, May, June, Sept., Nov. or December and as result there is a gap for each of those months. I'd like to hide these gaps and have the existing bars display side by side.
I've tried adding a conditional statement to each month under the Visibility property (under Series Properties) and had no luck. Example:
=iif(isnothing(sum(fields!jan.Value)), true, false)
Any help would be appreciated.
![1]: http://i.stack.imgur.com/ZrSXN.png
Couldn't you filter out the data at the chart level and/or the category group level. Then it wouldn't get included in the rendering of the chart. You can filter on Sum(field) = 0 or whatever the appropriate aggregation is that you are using.