I’d like to create a database (Access 97) that captures the Windows User ID when someone creates a new record on a form. I’ve put the code within a module as instructed but am not sure if it works properly.
how could it be this simple! I spent ages and ages and in the end found a code that I thought would fix it but gave me the machine Id, then I spent more time looking at found this code:
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)
fOSUserName = ""
WHAT A LONG AND DRAWN OUT PROCESS WHEN I COULD SIMPLY HAVE DONE Environ("UserName")