How to use system username directly in MS Access query?

You need to create a VBA function that returns the username, and then use the function in the query.

Public Function GetUserName() As String
    ' GetUserName = Environ("USERNAME")
    ' Better method, see comment by HansUp
    GetUserName = CreateObject("WScript.Network").UserName
End Function

and

SELECT foo FROM bar WHERE myUserName = GetUserName();

Leave a Comment