无法获得DLookup值与变量字段
我有一个名为BAF_User与2个字段(BAFUser,BRID)在Access中的用户窗体。无法获得DLookup值与变量字段
我使用下面的代码来获取Windows用户名,然后使用DLookup进行比较,并获取登录到Access文件的用户的全名。
Option Compare Database Public Function GetUserName() As String
Dim wshNet As Object
Dim As String
Set wshNet = CreateObject("WScript.Network")
GetUserName = wshNet.UserName
Set wshNet = Nothing
MyName = DLookup("[BAFUser]", "BAF_User", "[BRID] = '" & GetUserName & " '")
End Function
Private Sub Form_Load()
MsgBox "Welcome" + MyName
End Sub
但是这没有显示价值,我无法捕捉到我做错了什么。
感谢您的帮助。
回答:
为什么使用全局变量?只需调用该函数并让它返回值。
Public Function GetUserName() As String Dim wshNet As Object
Set wshNet = CreateObject("WScript.Network")
GetUserName = DLookup("[BAFUser]", "BAF_User", "[BRID] = '" & wshNet.UserName & "'")
Set wshNet = Nothing
End Function
Private Sub Form_Load()
MsgBox "Welcome " & GetUserName
End
一种替代方案:MsgBox "Welcome " & DLookup("[BAFUser]", "BAF_User", "[BRID] = '" & Environ("USERNAME") & "'"
以上是 无法获得DLookup值与变量字段 的全部内容, 来源链接: utcz.com/qa/257769.html