如何在 Access vba 中获取登录用户名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/677112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get logged-in user's name in Access vba?
提问by Varun Mahajan
Possible Duplicate:
Is there a way for MS Access to grab the current Active Directory user?
I want to get the name of the logged-in User via vbain access. What is the best way to do this?
我想通过vbain access 获取登录用户的名称。做这个的最好方式是什么?
Duplicates of this question:
这个问题的重复:
回答by JoshJordan
Try this:
尝试这个:
Function UserNameWindows() As String
UserName = Environ("USERNAME")
End Function
回答by Mitch Wheat
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?
原来之前有人问过这个问题:如何在 Access VBA 中获取当前登录的 Windows 用户?
回答by Sam
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
它将在文本框/标签中显示当前用户登录名,并将用户名保存在表字段中

