databasedev.co.uk - database solutions and downloads for microsoft access

Database Opening Message

Display Welcome Message at database Start-Up:

In a previous article - How to add a Welcome Message for your Database User's we showed you how to add and display a message dependant on the system time of the user computer.

Recently, Keith Wilby (Microsoft Access Database Design by Keith Wilby) submitted an improved, alternative solution to this sample whereby we need only one label and set it's 'caption' property accordingly.

If we create a form, adding a label to the form (naming the label lblGreeting as per the following code example), and add the code below to the form's OnLoad event procedure:

Private Sub Form_Load()
'---------------------------------
'You need only one label and set it's 'caption' property accordingly.
'You also only need to interrogate the system time function once,
'thereby speeding up the whole process
'In the form's On Load event:
'Keith Wilby.
'www.keithwilby.org.uk
'---------------------------------
Dim varTime As Variant, strLegend As String

varTime = Time()

    If varTime > "00:00:01" And varTime < "12:00" Then strLegend = "Good Morning"
    If varTime >= "12:00" And varTime < "18:00" Then strLegend = "Good Afternoon"
    If varTime >= "18:00" And varTime < "23:59" Then strLegend = "Good Evening"

Me.lblGreeting.Caption = strLegend

End Sub

Using this method you also only need to interrogate the system time function once, thereby speeding up the whole process.