Greeting bases on current time on switchboard

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
 
S

Steve Schapel

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
 
D

Dirk Goldgar

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()
 
D

Dirk Goldgar

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"?
 
D

Dirk Goldgar

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.
 
J

Jan Il

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? ;-))
 
J

Jeff Conrad

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
 
J

Jeff Conrad

Well you know how those "older" people need those naps...

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

Jeff Conrad
Bend, Oregon
 
S

Steve Schapel

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
 

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