USERNAME

Returns either the application user name or the network domain name.

'sType - The type of username you want to return.

Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Public Function UserName(ByVal sType As String) As String

Dim sBuffer As String * 255
Dim lLength As Long
Dim sUserName As String

   If (UCase(sType) = "APPLICATION") Then
      UserName = Application.UserName
   End If
   
   If (UCase(sType) = "DOMAIN") Then
      sUserName = ""
      lLength = GetUserName(sBuffer, 255)
      lLength = InStr(1, sBuffer, Chr(0))
      If (lLength > 0) Then
          sUserName = Left(sBuffer, lLength - 1)
      Else
          sUserName = sBuffer
      End If

      UserName = UCase(Trim(sUserName))
    End If
End Function

The application username can be seen from the (Tools > Options)(General tab).
The network username can be seen from ..


UserName("Application") = "Russell Proctor"
UserName("Domain") = "proctorr"


© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited TopPrevNext