Get user's first name and display message depend on time of the day

  • Thread starter Thread starter Song Su
  • Start date Start date
S

Song Su

I have a main form and I'd like to put 2 controls.

The 1st control, I want to say: Good Morning or Evening, Firstname

mid-night to 12noon say morning and 12noon to mid-night say evening.
'first name' is user's first name when then log into network (LAN). If first
name is impossible, network username is my 2nd choice

The 2nd control, I want to display current date/time.

However, I put =now() and format to 'general date', the second does not
change. Any way to let the clock change the second? If not, I have to just
format to show date only.

Any help on any of these controls would be appreciated.

Song Su
 
Song said:
I have a main form and I'd like to put 2 controls.

The 1st control, I want to say: Good Morning or Evening, Firstname

mid-night to 12noon say morning and 12noon to mid-night say evening.
'first name' is user's first name when then log into network (LAN). If first
name is impossible, network username is my 2nd choice

The 2nd control, I want to display current date/time.

However, I put =now() and format to 'general date', the second does not
change. Any way to let the clock change the second? If not, I have to just
format to show date only.


1) Try using an expressio in the text box:

="Good " & IIf(Hour(Time() < 12, "Morning", "Evening") &
", " & strFirstName

Use the function at
http://www.mvps.org/access/api/api0008.htm
to retrieve the login name.

2) Instead of an expression, use the form's Timer event to
set the clock text box's value. Set the form's
TimerInterval property to at least 1000 and use timer event
code like:
Me.txtClock = Now

Very Important Note:
Be sure to close (or switch to design view) all form's
that have a running timer event before attempting to make
any code chages in any module. It might be a good idea to
place a button on the form the set's the TimerInteral to 0.
Make the button invisible when you're about to distribute
your app.
 
Thank you for your quick response.

1. I forgot 'afternoon'. which time frame count as afternoon and how to code
it?

2. I set up a TimerInterval property to 1000 and add following code
Private Sub Form_Timer()
Me.txtClock = Now
End Sub
and on my form, i have a textbox called txtClock with following control
course:
=Format(Now(),"General Date")

When I open the form, the error message says 'You cannot assign a value to
the object' and it pointed to Me.txtClock=Now

What I'm doing wrong?

Thanks.

Song Su
 
1) It's sort of up to you to decide when you want afternoon to end, and
evening to begin.

Once you've decided, try:

="Good " & IIf(Hour(Time()) < 12, "Morning", IIf(Hour(Timer()) < 16,
"Afternoon", "Evening")) & ", " & strFirstName

2) You don't need the control source for the text box.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Song Su said:
Thank you for your quick response.

1. I forgot 'afternoon'. which time frame count as afternoon and how to
code it?

2. I set up a TimerInterval property to 1000 and add following code
Private Sub Form_Timer()
Me.txtClock = Now
End Sub
and on my form, i have a textbox called txtClock with following control
course:
=Format(Now(),"General Date")

When I open the form, the error message says 'You cannot assign a value to
the object' and it pointed to Me.txtClock=Now

What I'm doing wrong?

Thanks.

Song Su
 
Great! Now it's working. Final point:

The txtClock ticking now. However, some seconds, it flashes (white flash),
other seconds, it does not.

I set txtClock control as transparent already. Any idea?

Thanks.

Douglas J. Steele said:
1) It's sort of up to you to decide when you want afternoon to end, and
evening to begin.

Once you've decided, try:

="Good " & IIf(Hour(Time()) < 12, "Morning", IIf(Hour(Timer()) < 16,
"Afternoon", "Evening")) & ", " & strFirstName

2) You don't need the control source for the text box.
 

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