将用户名设置为Access表中的默认值 [英] Set username as default value in Access table

查看:96
本文介绍了将用户名设置为Access表中的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个访问表,其列为username.我有多个用户将在不同时间使用数据库,他们将向表中添加行.但是,每次用户添加新行时,其用户名都必须出现在表的用户名列中,而无需他们自己输入.我尝试将UCase(Environ("USERNAME"))设置为默认值,但是Environ是一个未知函数.我在导出表时在VBA中使用此UCase(Environ("USERNAME"))来获取用户名.

I have an access table with a column username. I have multiple users that will use the database at different times and they will add rows to the table. But everytime a user add a new row, his/her username must appear in the username column of the table, without them having to type it in by themselves. I tried putting in UCase(Environ("USERNAME")) as the default value, but Environ is an unknown function. I use this UCase(Environ("USERNAME")) in VBA to get the user name when i export tables.

有什么办法可以将列的默认值设置为用户的用户名?

Is there any way i can set the deafult value of a column to a user's username?

推荐答案

创建公共功能,如这里:

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

,并使用=GetUserName()作为控件的默认值.

and use =GetUserName() as default value for the control.

这篇关于将用户名设置为Access表中的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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