How to get windows username in MS Access VBA on Wi

2019-03-03 14:35发布

问题:

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