3 Answers3

47

Try this:

Function UserNameWindows() As String
     UserName = Environ("USERNAME")
End Function
JoshJordan
  • 12,676
  • 10
  • 53
  • 63
24
Public Declare Function GetUserName Lib "advapi32.dll" 
    Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

....

Dim strLen As Long
Dim strtmp As String * 256
Dim strUserName As String

strLen = 255
GetUserName strtmp, strLen
strUserName = Trim$(TrimNull(strtmp))

Turns out question has been asked before: How can I get the currently logged-in windows user in Access VBA?

Community
  • 1
  • 1
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
-3

In a Form, Create a text box, with in text box properties select data tab

Default value =CurrentUser()

Current source "select table field name"

It will display current user log on name in text box / label as well as saves the user name in the table field

McGarnagle
  • 101,349
  • 31
  • 229
  • 260
Sam
  • 11
  • 1
  • 6
    This does not display the current user's name; it returns the "name of the current user of the database". This defaults to "Admin" unless you've established a security-enabled workgroup. – Paul Jan 21 '13 at 18:51