papadega3000
Registered User.
- Local time
- Today, 14:03
- Joined
- Jun 21, 2007
- Messages
- 80
I am trying to build a function that allow me to compare dates and based on the dates relevance to current date. I have a table that has several fields of dates and I wanted to be able to color code them accordingly.
My questions are I want to be able to do this in a form or series of subforms that will query the database for all the dates and in the table and then run a function that will determine the color of the font needed for that date.
Would this be possible to set up a form to do this task.
After researching a little bit I came up with this general code:
Public Sub CompareDate(chkDate As Date)
Dim TodayDate
Dim DateDiffer
Dim lngRed As Long, lngYellow As Long, lngGreen As Long
lngRed = RGB(255, 0, 0)
lngYellow = RGB(255, 255, 0)
lngGreen = RGB(0, 255, 0)
TodayDate = DateValue(Now()) ' sets current date in MM/DD/YYYY format
' gives the difference in terms of days
DateDiffer = DateDiff(DateInterval.Day, Now, chkDate)
If DateDiffer = 0 Then
' code to make the font color = yellow
' Me!SomeFieldName.ForeColor = lngYellow
ElseIf DateDiffer > 0 Then
' code to make the font color = red
'Me!SomeFieldName.ForeColor = lngRed
ElseIf DateDiffer < 0 Then
' code to make the font color = green
'Me!SomeFieldName.ForeColor = lngGreen
End Sub
The intention here is the insert this into a module and then call this function the repeatly run through all the date fields and edit the colors each time the query is run.
How would I go about approaching the task of setting up a loop interate through a field?
Thanks for your help in advance.
My questions are I want to be able to do this in a form or series of subforms that will query the database for all the dates and in the table and then run a function that will determine the color of the font needed for that date.
Would this be possible to set up a form to do this task.
After researching a little bit I came up with this general code:
Public Sub CompareDate(chkDate As Date)
Dim TodayDate
Dim DateDiffer
Dim lngRed As Long, lngYellow As Long, lngGreen As Long
lngRed = RGB(255, 0, 0)
lngYellow = RGB(255, 255, 0)
lngGreen = RGB(0, 255, 0)
TodayDate = DateValue(Now()) ' sets current date in MM/DD/YYYY format
' gives the difference in terms of days
DateDiffer = DateDiff(DateInterval.Day, Now, chkDate)
If DateDiffer = 0 Then
' code to make the font color = yellow
' Me!SomeFieldName.ForeColor = lngYellow
ElseIf DateDiffer > 0 Then
' code to make the font color = red
'Me!SomeFieldName.ForeColor = lngRed
ElseIf DateDiffer < 0 Then
' code to make the font color = green
'Me!SomeFieldName.ForeColor = lngGreen
End Sub
The intention here is the insert this into a module and then call this function the repeatly run through all the date fields and edit the colors each time the query is run.
How would I go about approaching the task of setting up a loop interate through a field?
Thanks for your help in advance.