Say Good morning, Good afternoon! (1 Viewer)

Sohaila Taravati

Registered User.
Local time
Today, 23:26
Joined
Oct 24, 2001
Messages
266
I have a form that when the user opens it up it recognizes their name. How can I make the form tell them Good morning or good afternoon Mr/Mrs Brown. I know I probably have to put a field on the form that =Time() and an If statement that by looking at the field would recognize if it is morning or afternoon. Can anybody help? Thank you in advance
 

Alexandre

Registered User.
Local time
Tomorrow, 06:26
Joined
Feb 22, 2001
Messages
794
You do not necessarily need to place a control holding the time on your form. Checking for the current time in, for example, the on open event of your form should be enough:

If Time()> #12:00:00# then
Msgbox "Good Afternoon"
else
MsgBox "Good Morning"
End if

Alex

[This message has been edited by Alexandre (edited 02-21-2002).]
 

Graham T

Registered User.
Local time
Today, 23:26
Joined
Mar 14, 2001
Messages
300
I created a form and included 3 labels that are displayed dependant on the time.

The labels used - lblMorning, contains the caption of "Good Morning"; lblAfternoon contains the caption of "Good Afternoon" and lblEvening contains "Good Evening" as the caption.

The code attached to the forms On_Activate event is as follows:

Private Sub Form_Activate()

'When the database is opened displays welcome user message.

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

This works fine and shows the greating directly on the form, rather than opening up a message box.

HTH

Graham

[This message has been edited by Graham T (edited 02-22-2002).]
 

ColinEssex

Old registered user
Local time
Today, 23:26
Joined
Feb 22, 2002
Messages
9,110
You could do a really fancy splash form with the appropriate text and hold it open for a few seconds using the timer, when the database is opened.

Colin
 

BukHix

Registered User.
Local time
Today, 19:26
Joined
Feb 21, 2002
Messages
379
To get the username into the message you could do it whith something like this:

Code:
Dim strName
'set the variable to whatever control holds the username
strName = "BukHix"
'something like strName = txtUserName


If Time() > #12:00:00 PM# Then
    MsgBox "Good Afternoon" & " " & strName
Else
    MsgBox "Good Morning" & " " & strName
End If
 

Tiprof

Member
Local time
Today, 23:26
Joined
Apr 29, 2022
Messages
43
I created a form and included 3 labels that are displayed dependant on the time.

The labels used - lblMorning, contains the caption of "Good Morning"; lblAfternoon contains the caption of "Good Afternoon" and lblEvening contains "Good Evening" as the caption.

The code attached to the forms On_Activate event is as follows:

Private Sub Form_Activate()

'When the database is opened displays welcome user message.

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

This works fine and shows the greating directly on the form, rather than opening up a message box.

HTH

Graham

[This message has been edited by Graham T (edited 02-22-2002).]
With reference to this, I tried the code but seems not to work when the form is already opened.
Say, the form was opened in the morning and still using it during the afternoon.

how will I apply this code to automatically display as afternoon when is 12pm without me having to close the database and opening again?

The code help to display the time of the day when it is loaded but not when it is already opened
 

theDBguy

I’m here to help
Staff member
Local time
Today, 16:26
Joined
Oct 29, 2018
Messages
21,358
With reference to this, I tried the code but seems not to work when the form is already opened.
Say, the form was opened in the morning and still using it during the afternoon.

how will I apply this code to automatically display as afternoon when is 12pm without me having to close the database and opening again?

The code help to display the time of the day when it is loaded but not when it is already opened
You may have to use another event to do that. For example, one possible approach is to use the Form's Timer event.
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 18:26
Joined
Feb 28, 2001
Messages
27,001
Another choice is if the form is bound, it will have a Form_Current event that will fire every time you update the data in the form or navigate to a new record. Put your test there.
 

Gasman

Enthusiastic Amateur
Local time
Today, 23:26
Joined
Sep 21, 2011
Messages
14,048
Wow, a twenty year old thread resurrected.
That has to be the record surely.

Could even be a crosspost?
 

Tiprof

Member
Local time
Today, 23:26
Joined
Apr 29, 2022
Messages
43
You may have to use another event to do that. For example, one possible approach is to use the Form's Timer event.
Thought same
But I tried applying the code in the timer but nothing happens.
Am sure I didn’t apply the code well in the timer

any suggestions?
 

Tiprof

Member
Local time
Today, 23:26
Joined
Apr 29, 2022
Messages
43
Another choice is if the form is bound, it will have a Form_Current event that will fire every time you update the data in the form or navigate to a new record. Put your test there.
I have tried of the form’s Current event but didn’t work
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:26
Joined
Feb 19, 2013
Messages
16,553
Other than the timer event other events only fire when the user does something- current event fires when the focus changes to a new user.

if this in an ‘information’ form on a screen on the wall, the only event that will be triggered is the timer event

if the user is interacting with the form, choose an event linked to that interaction- might be a control got focus, a button click - or both
 

Tiprof

Member
Local time
Today, 23:26
Joined
Apr 29, 2022
Messages
43
Another choice is if the form is bound, it will have a Form_Current event that will fire every time you update the data in the form or navigate to a new record. Put your test there.
I have tried of the form’s Current event but didn’t work
Other than the timer event other events only fire when the user does something- current event fires when the focus changes to a new user.

if this in an ‘information’ form on a screen on the wall, the only event that will be triggered is the timer event

if the user is interacting with the form, choose an event linked to that interaction- might be a control got focus, a button click - or both
the form is an information form
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 07:26
Joined
May 7, 2009
Messages
19,169
you only need to set the TimerInterval once, in the morning, afternoon and evening:
don' use current event, use Load event to initialize the timer event:
Code:
' arnelgp
Private Sub Form_Load()
Call Form_Timer
End Sub

' arnelgp
' set the TimerInterval only Once in the morning, Afternoon and evening
'
Private Sub Form_Timer()
Dim d As Variant, t As Variant, TimerCountDown As Single
Dim greet As String
d = Now
t = TimeValue(d)
Select Case True
Case t < #12:00:00 PM#
    greet = "Morning"
    TimerCountDown = DateDiff("s", t, #12:00:00 PM#)
Case t < #5:00:00 PM#
    greet = "Afternoon"
    TimerCountDown = DateDiff("s", t, #5:00:00 PM#)
Case Else
    greet = "Evening"
    TimerCountDown = DateDiff("s", d, (DateValue(d) + 1) + #12:00:00 AM#)
End Select
TimerCountDown = TimerCountDown * 1000
Me.Auto_Header0.Caption = "Good " & greet & "!"
Me.TimerInterval = TimerCountDown
'Debug.Print TimerCountDown
End Sub
 

CJ_London

Super Moderator
Staff member
Local time
Today, 23:26
Joined
Feb 19, 2013
Messages
16,553
the form is an information form

So you need to use the timer event - presumably data needs to be refreshed on a frequent basis

But I tried applying the code in the timer but nothing happens.
Am sure I didn’t apply the code well in the timer

any suggestions?
would help if you showed what you tried - but I would expect

a textbox control called say txtDateTime with a controlsource of =Now() - or use =Time() if you only want to see the time

set the timerinterval in the form open event event

Code:
me.timerinterval=60000' so fires every minute

in the form timer event

Code:
me.requery 'refreshes all the controls on the form

and/or if you want a specific message dependant on the time

Code:
If Time() < 0.5 Then 'before midday
     me.greeting="Good Morning" 'where greeting is the name of an unbound textbox
ElseIf Time() < 0.75 Then 'before 6pm
      me.greeting="Good Afternoon"
Else'after 6pm
      me.greeting="Good Evening"
End If
 
Last edited:

Tiprof

Member
Local time
Today, 23:26
Joined
Apr 29, 2022
Messages
43
So you need to use the timer event - presumably data needs to be refreshed on a frequent basis


would help if you showed what you tried - but I would expect

a textbox control called say txtDateTime with a controlsource of =Now() - or use =Time() if you only want to see the time

set the timerinterval in the form open event event

Code:
me.timerinterval=60000' so fires every minute

in the form timer event

Code:
me.requery 'refreshes all the controls on the form

and/or if you want a specific message dependant on the time

Code:
If Time() < 0.5 Then 'before midday
     me.greeting="Good Morning" 'where greeting is the name of an unbound textbox
ElseIf Time() < 0.75 Then 'before 6pm
      me.greeting="Good Afternoon"
Else'after 6pm
      me.greeting="Good Evening"
End If
At this point, i tink is best i attach a copy of my initial database for analysis. because am still having vhallenges
 

Tiprof

Member
Local time
Today, 23:26
Joined
Apr 29, 2022
Messages
43
This is a sample of the original database i used for analysis. Would be glad if anyone could help me with a fix around it. Thanks
 

Attachments

  • MY SYSTEM.accdb
    864 KB · Views: 71

arnelgp

..forever waiting... waiting for jellybean!
Local time
Tomorrow, 07:26
Joined
May 7, 2009
Messages
19,169
here check the code.
 

Attachments

  • MY SYSTEM.accdb
    864 KB · Views: 73

Users who are viewing this thread

Top Bottom