on activate event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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
 
Back
Top