I had an interesting problem today with a client.
I have set up security and privilege on a database depending on NT User Login. However, I've only just realised that the code returns the profile name and not the login name. This company has the profile name "USER" generic to its profiles for some strange reason. It may be a group issue, I'm not network savvy.
Does anyone know of a way of retrieving the actual login name.
The code I am using is the standard code as below ...
Expand|Select|Wrap|Line Numbers
- Declare Function GetUserName& Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long)
- Function sys_OrigUserID() As String
- On Error GoTo Err_sys_OrigUserID
- ' Returns the username of the current logged in user.
- Dim s$, cnt&, dl&
- Dim max_String As Integer
- Dim usename As String
- max_String = 30
- cnt& = 199
- s$ = String$(max_String, 1)
- dl& = GetUserName(s$, cnt)
- usename = Trim$(left$(s$, cnt))
- usename = UCase(Mid(usename, 1, Len(usename) - 1))
- sys_OrigUserID = usename
- Exit_sys_OrigUserID:
- Exit Function
- Err_sys_OrigUserID:
- Select Case Err
- Case 0 '.insert Errors you wish to ignore here
- Resume Next
- Case Else '.All other errors will trap
- Beep
- MsgBox Err.Description, , "Error in Function SystemCode.sys_OrigUserID"
- Resume Exit_sys_OrigUserID
- End Select
- Resume 0 '.FOR TROUBLESHOOTING
- End Function