Access VB似乎没有从数据库中读取

时间:2017-01-10 19:59:44

标签: ms-access access-vba

Set rst = CurrentDb.OpenRecordset("SELECT role" & _
        " FROM EMP " & _
        " WHERE id =" & Chr(34) & id & Chr(34))

If rst.Fields(role) = "admin" Then
    cmdConnecterPrivilege.Visible = True
Else
    cmdConnecterPrivilege.Visible = False
End If

我做错了什么?谢谢!我想看看这名员工是否是管理员

1 个答案:

答案 0 :(得分:0)

您需要正确的语法,其中包括:

If rst.Fields("role") = "admin"
If rst("role") = "admin"
If rst!role = "admin"

但是你可以使用一个代码行完成这个简单的任务:

cmdConnecterPrivilege.Visible = (Nz(DLookup("role", "EMP", "ID = '" & id & "'")) = "admin")
相关问题