Results 1 to 10 of 10
  1. #1
    Join Date
    Feb 2009
    Posts
    28

    Unanswered: Put Name from "Security Setting" Into Field

    Is there a way to automatically put the users name into a field when a person leaves it?

    I have a small database to journal activities. But different people use it and make entries. So if Bob Jones is logged into it and after he makes an entry I'd like to it to put something along the lines of "-Bob Jones" (without the quotation marks) at the end.

    I'm guessing it'd be something that it would be something that would go into the On Lost Focus event.

    Any ideas?

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    I would do it when the record is updated (BeforeUpdate).

    Do you have your own login screens or are you using the Access workgroup type logging in?
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Feb 2009
    Posts
    28
    I'm using the Access workgroup login. And I'll go with your recomendation, as I'm pretty much clueless.

  4. #4
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    there is some code to grab the users netwrok logon (or if you don't use a network the username when the OS starts.

    it can be found in the code bank from Paul Kohn (PKStormy) or do a google for dev ashish API code

    you call the relevent function it returns the user id.. there are other functions there which can also return the computer ID, which has to be unique. so you can have a mechanism which ties down what userid and waht computer did what activity at what time.

    as to where you place the call to that function.. I'd agree wih StrarTrekker that the correct place is the before update event. whether you make it the control or form is arguable.

    I'd exect the code to be something like
    if length(mycontrol.value)>0 then ' do nothing
    else
    mycontrol.value = getusername
    'or if you prefer
    mycontrol.value = getusername & " did the dirty deed at " & format(now(),"dd/mmm/yyyy @ HH:MM: SS") & " on this computer: " & getcomputername
    'or whatever you need to log
    endif


    there wll be faults with the above code.. its not tested its all air code
    I'd rather be riding on the Tiger 800 or the Norton

  5. #5
    Join Date
    Feb 2009
    Posts
    28
    I like the idea of pulling from the network logon and saw PKStormy's code. It'll save me having to do it from the security settings.

    I'll mess with it a bit and see what happens. My biggest question is can it (or will it) place the code in the memo box and then can a person enter what they want.

  6. #6
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    in short you can do (virtually) whatever you want in Access. sometimes Access makes it easy for you, sometimes it doesn't. but you are primarily limited by your imagination or knowledge, rarely by Access itself.
    I'd rather be riding on the Tiger 800 or the Norton

  7. #7
    Join Date
    Feb 2009
    Posts
    28
    Luckily Access isn't limited. But my knowlege certainly is. Luckily there's this forum. I'll post back with my results.

  8. #8
    Join Date
    Feb 2009
    Posts
    28
    I believe I'm on the cusp of victory.

    Using some awesome code from PKStormy I have this module in my DB;

    Code:
    Function GetUser() As String
    '** Procedure to Get the User's Name from the Windows Login
    Dim si As SystemInfo
    Set si = New SystemInfo
    Dim strOut As String
    'strGetUser = si.UserName
    'strOut = si.UserName & " is logged into " & si.ComputerName
    GetUser = si.UserName
    If GetUser = "" Then
        MsgBox ("There is a problem with your Network Login Name!! Please contact your Network Administrator.")
        DoCmd.Quit
    End If
    End Function
    and this syntax (is that the right word?)
    Code:
    =getuser()
    In the default value.

    Thanks to PKStormy for placing that code in the code bank.
    http://www.dbforums.com/6274790-post20.html

    *Now* how do I have it automatically insert a new line (so the user name is at the top)? And I may be pushing my luck but is there a way to add a ":" or "-" at the end of the user name?
    Last edited by ffemtjacque; 02-11-09 at 12:08. Reason: Added another question

  9. #9
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    myusername = myusername & ":"
    or
    myusername = myusername & "-"
    or
    myusername = getuser() & ":"
    or
    myusername = getuser() & " added this turgid waffle at :" & format(now(),"HH:MMS") & " on the:" & format (now(),"dd mmm yyyy")
    the possibilities are endless.
    I've a sneaking suspiscion that you users may get a bit peeved if you use the last suggestion
    I'd rather be riding on the Tiger 800 or the Norton

  10. #10
    Join Date
    Feb 2009
    Posts
    28
    That was good for a laugh. Thanks for the help. I'll give it a shot this evening when I get home and will post back the results. Does it go into the default value or in the module code?

Posting Permissions

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