View Full Version : Say Good morning, Good afternoon!


Sohaila Taravati
02-21-2002, 12:58 PM
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 http://www.access-programmers.co.uk/ubb/smile.gif

Alexandre
02-21-2002, 01:18 PM
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
02-22-2002, 01:40 AM
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
02-22-2002, 03:45 AM
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
02-22-2002, 06:49 AM
To get the username into the message you could do it whith something like this:


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