Greeting bases on current time on switchboard

  • Thread starter Thread starter Harmannus
  • Start date Start date
H

Harmannus

Hallo,

Is it possible to create a greeting message based on current time in VBA? I
have a welcome <name> field on my switchboard. See code below. I would like
to have a text: Goodmorning <name>, Goodafternoon <name> or Goodevening
<name>.

Forms!Switchboard.lblWelcome.Caption = "Welcome " & GetUsrName()

Thanx for any tips!

Regards,
Harmannus
 
Harmannus,

Try this (untested!)...

Dim DayPart As String
If Time < #12:00 pm# Then
DayPart = "morning"
ElseIf Time < #6:00 pm# Then
DayPart = "afternoon"
Else
DayPart = "evening"
End If
Forms!Switchboard.lblWelcome.Caption = "Good " & DayPart & ", " &
GetUsrName()

- Steve Schapel, Microsoft Access MVP
 
Steve Schapel said:
Harmannus,

Try this (untested!)...

Dim DayPart As String
If Time < #12:00 pm# Then
DayPart = "morning"
ElseIf Time < #6:00 pm# Then
DayPart = "afternoon"
Else
DayPart = "evening"
End If
Forms!Switchboard.lblWelcome.Caption = "Good " & DayPart & ", " &
GetUsrName()

Or even

Forms!Switchboard.lblWelcome.Caption = _
"Good " & _
Switch(Time < #12:00PM#, "morning", _
Time<#5:00PM#, "afternoon", _
True, "evening") & _
", " & GetUserName()
 
Steve Schapel said:
I see you start your evening earlier than me, Dirk <g>

<lol> Yes, I couldn't help feeling that by the time we get to 5:00,
it's evening, not afternoon any more. The question is, should we add a
point -- 9:00 or 10:00 -- at which it becomes "night"?
 
Jan Il said:
hmm...and this makes a difference to night owls? ;-))

I didn't want to admit that sometimes it could be greeting me with "Good
morning" at 1:00PM.
 
Dirk Goldgar said:
<lol> Yes, I couldn't help feeling that by the time we get to 5:00,
it's evening, not afternoon any more. The question is, should we add a
point -- 9:00 or 10:00 -- at which it becomes "night"?

hmm...and this makes a difference to night owls? ;-))
 
Humm....that code looks familiar!

This must be from the sample file(s) I sent last month to
you Harmannus.
My apologies for not including this functionality in the
samples. This is really a strange coincidence, but I
actually have this type of greeting on my Switchboards! I
removed it from the samples since I didn't think anyone
else wanted it!! I guess I'll put it back on now!

Sorry about that.
Jeff Conrad
Bend, Oregon
 
Well you know how those "older" people need those naps...

(I'm outta here.....)

Jeff Conrad
Bend, Oregon
 
Seriously though, Dirk, in spite of your obviously questionable
personal habits <g>, I have learned something basic here from you, so
thanks a lot. I am not too proud to admit that I have previously used
Switch() only where the conditions were mutually exclusive, and had
somehow missed the fact that they are evaluated left-to-right. :-)

- Steve Schapel, Microsoft Access MVP
 
Back
Top