Results 1 to 4 of 4
  1. #1
    boxsta is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    9

    How to create a User Stamp


    Afternoon all.

    I have my access db set up with various forms/subforms/tables and all the rest of it but the one thing I'm really getting stuck on is the ability to user stamp a field in a subform. I can do date & time with Now() but in the next field across I also want to be able to stamp the name of the user that is currently logged into the db.

    Any ideas greatly appreciated. I'm no Access expert though, so I might struggle with code unless it's in simple terms

    Thanks

  2. #2
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    This is a section of Code that I got online that will get the Windows Username and/or computer name. Got it awhile ago and unfortunately don't remember exactly where. Hopefully another user here will recognize it and give the website. Once you've put this into Access you can call the functions from queries, Forms wherever you need them.

    Code:
    Option Compare Database
    Option Explicit
    
    Private Declare Function apiGetComputerName Lib "kernel32" Alias "GetComputerNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    
    
    Public Function GetComputerName() As String
    On Error Resume Next
        
        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
            GetComputerName = Left$(strCompName, lngLen)
        Else
            GetComputerName = "Unknown"
        End If
    
    End Function
    
    Public Function GetLoginName() As String
    On Error Resume Next
        
        Dim lngen As Long
        Dim lngX As Long
        Dim strUserName As String
        
        strUserName = String$(254, 0)
        lngen = 255
        lngX = apiGetUserName(strUserName, lngen)
        
        If lngX <> 0 Then
            GetLoginName = Left$(strUserName, lngen - 1)
        Else
            GetLoginName = "Guest"
        End If
    
    End Function

  3. #3
    alansidman's Avatar
    alansidman is offline Indifferent
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2010
    Location
    Steamboat Springs
    Posts
    2,538
    Here is another solution that might work for you

    http://www.datawright.com.au/access_..._in_access.htm

  4. #4
    boxsta is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    May 2012
    Posts
    9
    Thanks guys, hopefully Ill get that working just as soon as I've deciphered the code :-)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 04-30-2012, 12:57 PM
  2. Replies: 4
    Last Post: 12-19-2011, 12:16 PM
  3. Replies: 3
    Last Post: 09-22-2011, 03:35 PM
  4. create user interface from table
    By mer in forum Forms
    Replies: 5
    Last Post: 07-24-2011, 08:07 PM
  5. Replies: 22
    Last Post: 01-25-2011, 11:19 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums