Changing tracked user names to something more comprehensible

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LeighW
    New Member
    • May 2012
    • 73

    Changing tracked user names to something more comprehensible

    Hi all,

    I'm tracking any changes made to records within the database which includes user name and storing it within an archive table (tbl_Archive)

    To track the user name I'm using code I managed to find on this site within a form's module which works a treat and is shown below:

    Code:
    Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
    "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    Function fOSUserName() As String
    ' Returns the login name for Adminstrator use
    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 = vbNullString
    End If
    End Function
    What I'd also like to be able to do is change the names given (which as it's a company computer happens to be an incomprehensibl e set of alphanumerics) to the users actual name so it's easier to understand who made the edit.

    As this is going to be a private database with (at present) only a handful of users and the log-on name never changes, I'm guessing there must be a way of changing the names through a module or something.

    I tried to create my own like this:

    Code:
    Public Function UserNames()
    LK039384 = "Leigh Woodcock"
    End Function
    And then placed "UserNames" after the code above but it still came up with the jargon rather than my actual name.

    Any help would be much appreciated.

    Leigh
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You should create a user table. Then you can join your archive table to that on the user id to get the user's name. You won't have to edit your code every time a user is added or changed.

    Comment

    • LeighW
      New Member
      • May 2012
      • 73

      #3
      Of course! I don't know why I didn't think of that. My minds been too wrapped in VBA lately. That way it will be easy to introduce new names without getting into VBA.

      Thanks for the help Rabbit

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Sure thing. Good luck with your project.

        Comment

        Working...