Time Question

  • Thread starter Thread starter DS
  • Start date Start date
D

DS

I'm trying to set a Caption on a label based on the time of day..

If Me.TxtTime > 12:00AM and < 12:00PM Then
Me.LblGreeting.Caption ="Good Morning"
Elseif Me.TxtTime > 12:00PM and < 6:00PM Then
Me.LblGreeting.Caption ="Good Afternoon"
Elseif Me.TxtTime > 6:00PM and < 12:00AM Then
Me.LblGreeting.Caption ="Good Evening"
End If

Any help is appreciated to make this thing work.
Thanks
DS
 
Private Function Greetings() As String

Select Case TimeValue(Now())
Case Is < "12:00:00 PM"
Greetings = "Good Morning"
Case Is < "6:00:00 PM"
Greetings = "Good AfterNoon"
Case Else
Greetings = "Good Evening"
End Select
End Function

The to use it:

Me.lblGreeting.Caption = Greetings()
 
Klatuu gave a good function to work. I just thought I'd point out the
syntax error, incase you missed it:

If Me.TxtTime > 12:00AM and < 12:00PM Then


Needs to be:

If Me.TxtTime > #12:00 AM# and Me.TxtTime< #12:00 PM# Then
 
Klatuu gave a good function to work. I just thought I'd point out the
syntax error, incase you missed it:

If Me.TxtTime > 12:00AM and < 12:00PM Then


Needs to be:

If Me.TxtTime > #12:00 AM# and Me.TxtTime< #12:00 PM# Then






I tries the # but that puts the lines in red..still not working.
Thanks
DS
 
chirs,
The syntax is not incorrect. The function was tested before being posted.
In addition, the > < are not necessary. The Select Case statement executes
the code for the first true condition. The function as written does work and
returns the correct value.

DS,

I don't know how you are trying to use the function, but it does work. Can
you post back with your version so we can figure out why it is not working
for you.
 
Oops! I retract my last post. It does require #. I retested it and found
it works sometimes and not others. I apologize.

The comparison operators, however, are correct.
 
Klatuu,

The syntax error that I was referring to was in the OP's code. I was
referring to yours as i thought it would have worked and automatically
changed the string to a date format.


Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top