I found this code (Dev's?) for a module in an earlier post sometime in
the last month...
It works like a charm. It writes the Windows Login ID nicely.
The way I am using it is to call the code from a form where the user
is changing data. I then write the value (via a hidden text box) to a
record-level field.
_______________________________________________________________________________________
Option Explicit
Private Declare Function WinAPI_GetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function NetworkUserName() As String
Dim iStringLength As Long, i As Long
Dim sString As String
sString = String(255, 0)
iStringLength = Len(sString)
sString = Space$(iStringLength)
If WinAPI_GetUserName(sString, iStringLength) Then
i = InStr(sString, Chr(0))
If i Then
sString = Left(sString, i - 1)
End If
NetworkUserName = Trim(Left$(sString, iStringLength))
Else
NetworkUserName = "Unknown"
End If
End Function
Keith Wilby - 31 Oct 2007 09:09 GMT
>I found this code (Dev's?) for a module in an earlier post sometime in
> the last month...
... and if you want the user's database ID use the CurrentUser function.
Keith.
www.keithwilby.com