on activate event

C

Carol Shu

question: this on activate event works great, but when it is morning hours,
it show "good evening", then in the evening hours it show "good morning",
can't figure out why, please help.

Private Sub Form_Activate()
If Time() < 0.5 Then
[lblMorning].Visible = True
[lblAfternoon].Visible = False
[lblEvening].Visible = False

ElseIf Time() > 0.5 And Time() < 0.75 Then
[lblMorning].Visible = False
[lblAfternoon].Visible = True
[lblEvening].Visible = False

ElseIf Time() > 0.75 Then
[lblMorning].Visible = False
[lblAfternoon].Visible = False
[lblEvening].Visible = True
End If
End Sub
 
C

Carl Rapson

Carol Shu said:
question: this on activate event works great, but when it is morning
hours,
it show "good evening", then in the evening hours it show "good morning",
can't figure out why, please help.

Private Sub Form_Activate()
If Time() < 0.5 Then
[lblMorning].Visible = True
[lblAfternoon].Visible = False
[lblEvening].Visible = False

ElseIf Time() > 0.5 And Time() < 0.75 Then
[lblMorning].Visible = False
[lblAfternoon].Visible = True
[lblEvening].Visible = False

ElseIf Time() > 0.75 Then
[lblMorning].Visible = False
[lblAfternoon].Visible = False
[lblEvening].Visible = True
End If
End Sub

I'm not sure what you're trying to do with the Time() function, but as far
as I can tell it returns the actual time of day, not a number between 0 and
1. I'd suggest doing something like this:

If Hour(Time()) <= 12 Then
' morning
Elseif Hour(Time()) > 12 And Hour(Time()) < 18 Then
' afternoon
Else
' evening
End If

Carl Rapson
 

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

Top