Teedee Access VBA Teedee 2010
Get Windows Login
Home Tutorial Code Snippets

Get Windows Logon

Returns the Logon Name of the current Windows user.



Code Snippet

Option Explicit Private Declare Function apiGetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Function GetWindowsLogonName() As String     ' Returns the network login name         Dim lng0 As Long, lng1 As Long     Dim sUsername As String         sUsername = String$(254, 0)     lng0 = 255     lng1 = apiGetUserName(sUsername, lng0)     If (lng1 > 0) Then         GetWindowsLogonName = Left$(sUsername, lng0 - 1)     Else         GetWindowsLogonName = ""                                      End If End Function
Place all code in a module and call the function from your code