Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2003
    Location
    London
    Posts
    341

    Unanswered: Recording Users who enter data

    Hi guys!

    In my database, I'm trying to keep an eye on who exactly is making mistakes within the system. I've currently got a code set up that records the computer ID but I would like the user logged on to be recorded.

    If it helps, the code I have at the moment is:

    Option Explicit
    Private Declare Function apiGetComputerName Lib "kernel32" Alias _
    "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long

    Function MachineName() As String
    'Returns the computername
    Dim lngLen As Long, lngX As Long
    Dim strCompName As String
    lngLen = 16
    strCompName = String$(lngLen, 0)
    lngX = apiGetComputerName(strCompName, lngLen)
    If lngX <> 0 Then
    MachineName = Left$(strCompName, lngLen)
    Else
    MachineName = ""
    End If
    End Function

  2. #2
    Join Date
    Aug 2004
    Location
    Manchester, England
    Posts
    23
    Try this...

    Option Compare Database

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

    Function fOSUserName() As String
    ' Returns the network login name
    Dim lngLen As Long, lngX As Long
    Dim strUserName As String
    strUserName = String$(254, 0)
    lngLen = 255
    lngX = apiGetUserName(strUserName, lngLen)
    If lngX <> 0 Then
    fOSUserName = Left$(strUserName, lngLen - 1)
    Else
    fOSUserName = ""
    End If
    End Function

    Cheers,

    JBee

  3. #3
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004

    Smile

    Hi JBee,

    Where would you place that code exactly? Within a text box to hold it or where? I want kinda the same thing but never figured out how to get the user name. If I place a TextBox on a form and call it User, how would I get that code to place the logged in user in that text box?

    thanks
    Bud

  4. #4
    Join Date
    Oct 2003
    Location
    London
    Posts
    341
    I created a new module and pasted the code into that.

    Within my table I created a field entryby.

    On the form that was going to record this, I created a new text box and made the record source entryby. I set the default value to:

    =FOSUserName()

    and then made the box invisible (visible=no).

    If you want to see if it works without creating a new record, just change the box to visible.

Posting Permissions

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