Colour Date Fields Based on Date Period with Row Render

Tips submitted by ASPMaker users

Colour Date Fields Based on Date Period with Row Render

Postby xgis » Mon Feb 25, 2013 5:46 pm

Below is a sample of colouring date fields based on time period. The example goes from days to weeks to months to years.
This sample uses a blue gradient. There are probably much better colour schemes for this sort of thing, including the option
to run multiple schemes based on different pastel gradients.

The code checks to see if there is any record. If the field is emtpty it uses an amber colour to show it is waiting for data.
Otherwise the remaining blue gradient goes from light grey-blue for recent dates, through to dark grey-blue for older dates.
The code could probably be better including the numbers but it works fine for a sample.

' Row Rendered event
Sub Row_Rendered()
If IsNull(DateCompleted.CurrentValue) Then
DateCompleted.CellCssStyle = "background-color: #FFCC00" '1 - NULL(Amber)
ElseIf DateCompleted.CurrentValue > Date - 1 Then
DateCompleted.CellCssStyle = "background-color: #CCDDDC" '2 - 1 Day
ElseIf DateCompleted.CurrentValue > Date - 3 Then
DateCompleted.CellCssStyle = "background-color: #C0CFCC" '3 - 3 Days
ElseIf DateCompleted.CurrentValue > Date - 7 Then
DateCompleted.CellCssStyle = "background-color: #B5C5C2" '4 - 1 Week
ElseIf DateCompleted.CurrentValue > Date - 14 Then
DateCompleted.CellCssStyle = "background-color:#AABAB7" '5 - 2 Weeks
ElseIf DateCompleted.CurrentValue > Date - 30 Then
DateCompleted.CellCssStyle = "background-color: #9FB0AD" '6 - 1 Month
ElseIf DateCompleted.CurrentValue > Date - 60 Then
DateCompleted.CellCssStyle = "background-color: #94A5A3" '7 - 2 Months
ElseIf DateCompleted.CurrentValue > Date - 90 Then
DateCompleted.CellCssStyle = "background-color: #8A9B98" '8 - 3 Months
ElseIf DateCompleted.CurrentValue > Date - 180 Then
DateCompleted.CellCssStyle = "background-color: #7F908E" '9 - 6 Months
ElseIf DateCompleted.CurrentValue > Date - 365 Then
DateCompleted.CellCssStyle = "background-color: #748684" '10 - 1 Year
ElseIf DateCompleted.CurrentValue > Date - 730 Then
DateCompleted.CellCssStyle = "background-color: #818D85" '11 - 2 Years
ElseIf DateCompleted.CurrentValue > Date - 1825 Then
DateCompleted.CellCssStyle = "background-color: #697B79" '12 - 5 years
ElseIf DateCompleted.CurrentValue > Date - 3650 Then
DateCompleted.CellCssStyle = "background-color: #536664" '13 - 10 years
End If
End Sub
xgis
 
Posts: 87
Joined: Thu Jan 17, 2013 10:40 pm

Return to User Submitted Tips (ASPMaker)