我正在尝试为我的访问数据库创建一个用户身份验证系统。目前我的表格有两个组合框“用户名”和“密码” 以及用于验证输入数据的按钮。我还有一个名为“Login”的表,其中包含所有用户名和密码以及它们的“级别”,这是它们的清除级别,它将决定表单的哪个版本以及其他信息。我不熟悉Dlookup并且收到错误“无效的外部过程”我是否可以将dlookup值作为可以在if语句中使用的字符串传递?
CODE:
Public Sub Command4_Click()
Dim usr As String
Dim lvl As String
Dim lck As Integer
usr = DLookup("Password", "Login", "Me.Username.Value= 'Username'")
lvl = DLookup("Level", "Login", "Me.Username.Value= 'Username'")
If usr = Me.Password.Value Then lck = 1
Do While lck = 1
If lvl = 3 Then
DoCmd.OpenForm "Main"
lck = 0
End If
Loop
End Sub
答案 0 :(得分:2)
尝试
usr = DLookup("[Password]", "Login", "[Username]='" & Me.Username.Value & "'" )
lvl = DLookup("[Level]", "Login", "[Username]='" & Me.Username.Value & "'")
答案 1 :(得分:1)
在HansUp Sensei的大力帮助和asdev的重要补充之后,我已经完成了基于表格的简单用户身份验证表单的工作代码。您可以添加级别并修改If
语句,以指定对数据库区域的适当访问权限。
Public Sub Command4_Click()
Dim usr As String
Dim lvl As String
Dim lck As Integer
usr = DLookup("[Password]", "Login", "[Username]='" & Me.Username.Value & "'")
lvl = DLookup("[Level]", "Login", "[Username]='" & Me.Username.Value & "'")
If usr = Me.Password.Value Then
lck = 1
Else
MsgBox ("Invalid Credentials")
End If
Do While lck = 1
If lvl = "3" Then
DoCmd.OpenForm "Main"
lck = 0
End If
Loop
End Sub