问题
I am using this code in my MS Access VBA: How to get logged-in user's name in Access vba?
It works perfectly fine. However, our foreign employees need to use the software on a server, and it is unable to retrieve the username. We are signed in as usual. The server version is Windows Server 2008 SP2.
Any suggestions?
Best regards, Emil.
回答1:
I don't know which method you are using (there are several answers), but this one suggested by HansUp is easy and hopefully works on the Server too:
https://stackoverflow.com/a/32565953/3820271
Public Function GetUserName() As String
' GetUserName = Environ("USERNAME")
' Better method, see comment by HansUp
GetUserName = CreateObject("WScript.Network").UserName
End Function
来源:https://stackoverflow.com/questions/34352511/how-to-get-windows-username-in-ms-access-vba-on-windows-server-2008