How to use system username directly in MS Access query?

前端 未结 4 1507
萌比男神i
萌比男神i 2020-11-28 15:57

I would like to know if there is a way to get system username and use it directly in an MS Access query. I have made a parameter work within a query from a combo box on a fo

4条回答
  •  一向
    一向 (楼主)
    2020-11-28 16:39

    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();
    

提交回复
热议问题