【发布时间】:2018-03-26 08:24:37
【问题描述】:
我在一个表单中有 2 个文本框,在表格 tbStudentLogs 中有 2 个字段。我想要做的是验证txtLoginID.Value 存在于StudentID 字段中。如果是这样,我想验证txtPassword.text 是否存在于txtLoginID.text 是StudentID 的同一记录中。这是我使用的code,但我修改了名称:
Private Sub Command15_Click()
If IsNull(Me.txtLoginID) Then
MsgBox "Please enter LoginID", vdInformation, "LoginID Required"
Me.txtLoginID.SetFocus
Else
'process the job
If (IsNull(DLookup("StudentID", "tbStudentLogs", "StudentID ='" & Me.txtLoginID.Value & "'"))) Or _
(IsNull(DLookup("SPassword", "tbStudentLogs", "SPassword = '" & Me.txtPassword.Value & "'"))) Then
'MsgBox "Incorrect LoginID or Password"
Else
'MsgBox "Login and Password Correct"
'Code to open new form etc,.
End If
End If
End Sub
但这不起作用。我得到的确切问题是:程序识别空字段,但我永远无法登录。换句话说,我无法到达最后一个Else 部分。由于密码和ID总是错误的。我检查了拼写等,但问题肯定出在我的代码中。是IsNull 部分吗?
编辑:
我意识到问题不在于我的代码。对于我的 StudentID,输入掩码是:
>\S00009
例如,用户拥有S0001 和密码1234。如果我输入用户名0001,也就是说,没有S,它就可以工作。否则,它不起作用。为什么?
现在请注意,没有“S”它也可以工作。
【问题讨论】:
标签: database ms-access login vba input-mask