我想在 MS Access 中设置用户登录访问权限,这意味着如果用户以管理员身份登录,它将显示不同的表单。
我试图获取userlevel
which 是一个字符串,并会显示类似"Admin"
或"User"
但它表示的内容:
无效使用 Null
在这一行:
UserLevel = DLookup("UserSecurity", "tblUser", "[UserLogin] = ' " & Me.txtLoginID.Value & "'")
这是完整的代码:
Private Sub Command1_Click()
Dim UserLevel As String 'get the dlookup value
Dim TempPass As String
If IsNull(Me.txtLoginID) Then
MsgBox "Please Enter Login ID", vbInformation, "Login Id Required"
Me.txtLoginID.SetFocus
ElseIf IsNull(Me.txtLoginPass) Then
MsgBox "Please Enter Password", vbInformation, "Login password Required"
Me.txtLoginPass.SetFocus
Else
'process the job
If (IsNull(DLookup("UserLogin", "tblUser", "UserLogin ='" & Me.txtLoginID.Value & "'"))) Or _
(IsNull(DLookup("password", "tblUser", "Password = '" & Me.txtLoginPass.Value & "'"))) Then
MsgBox "Incorrect Password"
Else
TempPass = DLookup("password", "tblUser", "UserLogin = '" & Me.txtLoginID.Value & "'")
UserLevel = DLookup("UserSecurity", "tblUser", "[UserLogin] = ' " & Me.txtLoginID.Value & "'")
'get the usersecurity whcih indicate he is admin or user
DoCmd.Close
If UserLevel = "Admin" Then 'if admin then open employee form else open customer form
'MsgBox "Login ID and password correct "
DoCmd.OpenForm "Employee"
Else
DoCmd.OpenForm "CustomerForm"
End If
End If
End If
End Sub
我曾尝试使用Nz()
,但它给了我一个空值,将我带到客户表单。