The creation and customization of database applications using Microsoft Access
Environ("USERNAME") is the VBA function used to return the value of the Windows environment variable for the signed-in user.
Key points:
-
Environ(envstring)returns the string associated with an operating system environment variable. - If the variable is not found, it returns an empty string (
""). - It is available in VBA, and is not available on Macintosh.
- In Access, if the Microsoft Jet Expression Service is running in sandbox mode, this function is disabled.
Example in VBA:
MsgBox Environ("USERNAME")
If the goal is the Access database user instead of the Windows sign-in name, use CurrentUser instead:
MsgBox CurrentUser
CurrentUser returns the current database user account name. If workgroup security is not established, it returns the default user account, Admin.
If the goal is specifically the network or Windows logon name, Access documentation also provides an approach using a user-defined function that calls the GetUserNameA Windows API.