Option Compare Database
Option Explicit
Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Public Function GetCurrentUserName() As String
Dim strName As String
Dim lngChars As Long
Dim lngRet As Long
strName = Space(255)
lngChars = 255
lngRet = GetUserName(strName, lngChars - 1)
If lngRet > 0 Then
GetCurrentUserName = Replace(strName, " ", "")
GetCurrentUserName = Replace(GetCurrentUserName, Chr$(0), "")
Else
GetCurrentUserName = "Unknow"
End If
End Function
|