Per John sd:
I would like to get the Current Logged In User (the login Id) to stamp a
record with the creation user.
The CurrentUser() function returns "Admin" instead of the Current Logged In
user that created the record.
I stopped bothering with the MS Access login and now always use
the LAN ID.
The code below is wretched excess - but that's what I started out
with and that's what I'm using now....
Hopefully, somebody else will chime in with a one-liner to do the
same thing:
------------------------------------------------------------
Private Declare Function GetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function CurrentUserGet() As String
1000 debugStackPush mModuleName & ": CurrentUserGet"
1001 On Error GoTo CurrentUserGet_err
' PURPOSE: To return the name of the person currently logged
' on.
' RETURNS: (you guessed it!)
'
' NOTES: 1) No sense going through any extra processing,
' so we work through the static and only invoke
' userIdWindowsGet() the first time.
' 2) We have a temporary workaround here.
' If somebody has Admin authority over their PC,
' the NetWare logon process logs them
' on to Windows as "Administrator" - creating a
' problem for us.
1002 Dim winUser As String
Static myCurrentUser As String
1010 If Len(myCurrentUser) = 0 Then
1011 winUser = userIdWindowsGet()
1019 myCurrentUser = winUser
1199 End If
1999 CurrentUserGet = myCurrentUser
CurrentUserGet_xit:
DebugStackPop
On Error Resume Next
Exit Function
CurrentUserGet_err:
BugAlert True, ""
Resume CurrentUserGet_xit
End Function
Private Function userIdWindowsGet() As String
debugStackPush mModuleName & ": userIdWindowsGet"
On Error GoTo userIdWindowsGet_err
' PURPOSE: To retrieve the Windows UserID of the person currently
' logged on to this PC
' RETURNS: UseID or empty string
Dim myBuffer As String * 255
Dim myUserName As String
GetUserName myBuffer, Len(myBuffer)
'Get the user name
myUserName = Left(Trim(myBuffer), InStr(myBuffer, Chr(0)) - 1)
'Trim excess characters
If Len(myUserName) > 0 Then
userIdWindowsGet = myUserName
Else
BugAlert True, "Unable to get Windows UserID"
End If
userIdWindowsGet_xit:
DebugStackPop
On Error Resume Next
Exit Function
userIdWindowsGet_err:
BugAlert True, ""
Resume userIdWindowsGet_xit
End Function