如何在Access vba中登录用户名?

时间:2009-03-24 12:10:01

标签: ms-access vba

3 个答案:

答案 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()

当前来源“选择表格字段名称”

它将在文本框/标签中显示当前用户登录名称,并在表格字段中保存用户名