如何在 MS Access 查询中直接使用系统用户名? [英] How to use system username directly in MS Access query?

查看:26
本文介绍了如何在 MS Access 查询中直接使用系统用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法获取系统用户名并直接在 MS Access 查询中使用它.我在表单上的组合框的查询中创建了一个参数,并且我还在 Access VBA 中使用 ENVIRON(USERNAME")获取了系统名称.

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 form and I have also acquired system name in Access VBA using ENVIRON ("USERNAME").

如果可行,请告诉我.

推荐答案

您需要创建一个返回用户名的 VBA 函数,然后在查询中使用该函数.

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

SELECT foo FROM bar WHERE myUserName = GetUserName();

这篇关于如何在 MS Access 查询中直接使用系统用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆