Results 1 to 11 of 11
  1. #1
    Star Lounger
    Join Date
    Oct 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Greeting message (97)

    Hi,
    I have a database that is opened by clicking on an icon. Is there anyway that a message can appear when the user opens it with something like "Good morning John" where it gets the name John from the user whos logged on that PC? and when its afternoon it says "Good afternoon John", ive windows NT if thats any help.
    Thanks for the help in advance,
    Rob.

  2. #2
    3 Star Lounger
    Join Date
    Dec 2001
    Location
    Royal Oak, Michigan, USA
    Posts
    255
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Greeting message (97)

    Here is code to use that will pull the person's Login ID:

    >>>>>>>>>>
    Option Compare Database

    Public Declare Function GetUserName Lib "advapi32.dll" _
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

    Function GetUser() As String
    Dim lpBuff As String * 255
    Dim ret As Long, UserName As String
    ret = GetUserName(lpBuff, 255)
    GetUser = Left(lpBuff, InStr(lpBuff, Chr(0)) - 1)
    End Function
    >>>>>>>>>>>>>

    You can then use a table with login IDs and user names to pull the person's name to get the greeting you are looking for. Then simply add a string to associate time with morning, afternoon, or evening.
    Let me know if this helps. If you need help on how to pull name and time of day, let me know.
    Dashiell

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Greeting message (97)

    1. To get the full user name, you can use the attached code. Copy the text into a standard module. The GetFullName function will return the full name of the logged in user.

    2. To get the time of day, you can use Hour(Time). This returns the hoour of the current time, in a 24 hour clock.

    3. You can open a form automatically when the database is opened - see Tools | Startup... You can set the caption of a label on this form in the On Load event:

    Private Sub Form_Load()
    Dim strDayPart As String
    Dim strUser As String
    Dim strMessage As String

    Select Case Hour(Now)
    Case 0 To 5
    strDayPart = "night"
    Case 6 To 11
    strDayPart = "morning"
    Case 12 To 17
    strDayPart = "afternoon"
    Case 18 To 23
    strDayPart = "evening"
    End Select

    strUser = GetFullName

    strMessage = "Good " & strDayPart & ", " & strUser
    lblWelcome.Caption = strMessage
    End Sub
    Attached Files Attached Files

  4. #4
    Star Lounger
    Join Date
    Oct 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Greeting message (97)

    Hi Hans
    Im not to sure where to add some of your code. I set up a form that appears when the database is started but nothing appears on the greeting form i tried adding a command button and added the code to it but nothing happened the code you gave me to pull the user name is in a module how do i link this to the intro form??
    Many thanks,
    Rob.

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Greeting message (97)

    It would be a good idea to brush up on the basics of programming in Access. Now that search is back, you should be able to find several threads with recommendations on books to read, although by now most available books will be for Access 2000 and up.
    <UL><LI>Activate the Modules tab of the database window.
    <LI>Create a new module.
    <LI>Copy the code from the text file I attached to my previous reply, and paste it into the new module.
    <LI>Close the module and save it as (for example)basFullName.
    <LI>Click on the Forms tab of the database window.
    <LI>Open the startup form in design view.
    <LI>Place a new label on the form; its caption can be anything you like, for example x.
    <LI>Set its Name to lblWelcome in the Other tab of the Properties window.
    <LI>Click in form window outside the form itself; you will see Form in the caption of the Properties window.
    <LI>Activate the Event tab of the Properties window.
    <LI>Click in the On Load event.
    <LI>Select Event Procedure from the dropdown list.
    <LI>Click the builder button (the three dots ... to the right of the dropdown arrow)
    <LI>The form module will open, with the first and last line of the event procedure already created for you.
    <LI>Copy the code to go between these lines from my previous reply, and paste it into the module.
    <LI>Switch back to the form window, close and save it.[/list]When you open the form now, it should display the appropriate greeting.
    Attached Images Attached Images
    • File Type: png x.png (3.3 KB, 1 views)

  6. #6
    Star Lounger
    Join Date
    Oct 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Greeting message (97)

    Hi Hans,
    That works fine now thanks, when i start the database the welcome form opens just for a milli second then minimises there is another form that opens also on startup maybe there is a conflict between them. How would i get the welcome form to appear on the screen without minimising?
    Do you know how i would get the welcome form to display exactly like yours i went into properties in the form design view and changed it and i got my welcome message to appear like this,
    Many thanks for the help,
    Rob
    Attached Images Attached Images

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Greeting message (97)

    There must be something that minimizes the welcome form and opens another form. Do you have an AutoExec macro?

    The relevant properties of the form are:

    <table border=0><td>Caption:</td><td>Welcome</td><td>Scroll Bars:</td><td>Neither</td><td>Record Selectors:</td><td>No</td><td>Navigation Buttons:</td><td>No</td><td>Auto Resize:</td><td>Yes</td><td>Auto Center:</td><td>Yes</td><td>Border Style:</td><td>Dialog</td></table>
    The relevant properties of the label lblWelcome are:

    <table border=0><td>Back Style:</td><td>Transparent</td><td>Special Effect:</td><td>Flat</td><td>Border Style:</td><td>Transparent</td></table>
    I have attached the demo I created.
    Attached Files Attached Files

  8. #8
    Star Lounger
    Join Date
    Oct 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Greeting message (97)

    Hi Hans,
    Thanks for the help there was an autoexe but i changed it so the greeting message didnt minimise. Do you know if there is anyway of making a message appear on a particular date? also can you make the welcome message disapear after say 2 secs so it saves the user having to close it down?
    Thanks for the help in advance,
    Rob.

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Greeting message (97)

    Do you want the startup form to be displayed only on certain days, or do you want to display an extra message on certain days? ("Happy Birthday, Hungry Hippos!")

    To make the form disappear after an interval of time, do the following:
    <UL><LI>Set the Timer Interval property of the form to the number of milliseconds you want it to stay open. For example, if you want to display it for 5 seconds, set Timer Interval to 5000. The Timer Interval property is in the Event tab of the Properties window.
    <LI>Write code to close the form in the On Timer event of the form:

    Private Sub Form_Timer()
    DoCmd.Close acForm, Me.Name, acSaveNo
    End Sub[/list]

  10. #10
    Star Lounger
    Join Date
    Oct 2003
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Greeting message (97)

    The timer works fine now thanks ,yes id like an extra message to appear in the same form for example from the 3rd to the 25th of December id like the following message ,

    Good afternoon and happy christmas, Hungry Hippos

    Cheers,
    Rob

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Greeting message (97)

    You can expand the code in the On Load event of the form. Additions to the original code are in bold:

    Private Sub Form_Load()
    Dim strDayPart As String
    Dim strUser As String
    Dim strExtra As String
    Dim strMessage As String

    Select Case Hour(Now)
    Case 0 To 5
    strDayPart = "night"
    Case 6 To 11
    strDayPart = "morning"
    Case 12 To 17
    strDayPart = "afternoon"
    Case 18 To 23
    strDayPart = "evening"
    End Select

    If Month(Date) = 12 And Day(Date) > 3 And Day(Date) < 26 Then
    strExtra = " and Merry Christmas"
    ElseIf Month(Date) = 1 And Day(Date) < 6 Then
    strExtra = " and a Happy New Year"
    End If

    strUser = GetFullName

    strMessage = "Good " & strDayPart & strExtra & ", " & strUser
    lblWelcome.Caption = strMessage
    End Sub

    You can add as many special date ranges as you like.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •