help with environ("username") in access database

James Speckmann 0 Reputation points
2026-09-26T23:15:19.0966667+00:00

I can't get this to work hopefully there are answers already to this ?

Microsoft 365 and Office | Access | Development
0 comments No comments

2 answers

Sort by: Most helpful
  1. Duane Hookom 26,940 Reputation points Volunteer Moderator
    2026-09-29T03:44:42.86+00:00

    “I can't get this to work” is too vague. What do you see that we don’t.

    I usually recommend the code at the Access Web.

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments

  2. AI answer

    2026-09-26T23:15:30.18+00:00

    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.


    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.