Access vba time function

I am trying to create a function that will allow me to set a field background color on a form its a time field so if its todays date and the class is today then the field will be:

green background upto 1 hour before
Amber background between 60 and 31 minutes before
red background 30 minutes and upto the start time.

One thing I have not figured out is how to make it so that the red works as described but once class has started then it just has normal white background ie no color, currently it stays red

Public Function getTimeStatus(St As Date, Dt As Date, Schedule_FK As Integer, Group As String) As Integer

Dim db As DAO.Database
Set db = CurrentDb
Dim RstHour As DAO.Recordset
Dim StrQuery As String
Dim cancelled As Integer

'St  is the start time of class
'Dt is the date of the class

cancelled = getCancelledStatus(Dt, Schedule_FK, Group)

If DateDiff("n", Time(), [St]) >= 60 And Format(Now(), "Short Date") = [Dt] Then
MsgBox ("green")
End If

If DateDiff("n", Time(), [St]) < 60 And DateDiff("n", Time(), [St]) >= 30 And Format(Now(), "Short Date") = [Dt] Then
MsgBox ("amber")
End If


If DateDiff("n", Time(), [St]) < 30 And Format(Now(), "Short Date") = [Dt] Then
MsgBox ("red")
End If

If Now() > [St] Then
MsgBox ("after")
End If

If cancelled = 0 And Dt >= Format(Now(), "Short Date") Then


End If

End Function

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


pls try
If DateDiff("n", Time(), [St]) < 30 And DateDiff("n", Time(), [St]) >= 0 And Format(Now(), "Short Date") = [Dt] Then

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PeterBaileyUkAuthor Commented:
great thank you I just couldn't see it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.