可能重复:
Is there a way for MS Access to grab the current Active Directory user?
我想通过vba中的access获取已登录用户的名称。这样做的最佳方式是什么?
这个问题的重复:
答案 0 :(得分:43)
试试这个:
Function UserNameWindows() As String
UserName = Environ("USERNAME")
End Function
答案 1 :(得分:21)
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))
之前已经提出问题:How can I get the currently logged-in windows user in Access VBA?
答案 2 :(得分:-3)
在表单中,创建一个文本框,在文本框属性中选择数据选项卡
Default value =CurrentUser()
当前来源“选择表格字段名称”
它将在文本框/标签中显示当前用户登录名称,并在表格字段中保存用户名