【问题标题】:Input mask literal character not found in DLookup?在 DLookup 中找不到输入掩码文字字符?
【发布时间】: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,它就可以工作。否则,它不起作用。为什么?


至于 Erik 的回答,这是我得到的:

现在请注意,没有“S”它也可以工作。

【问题讨论】:

    标签: database ms-access login vba input-mask


    【解决方案1】:

    最可能的问题是您对可能包含数字的字段使用字符串分隔符,因此总是返回 Null

    DLookup("StudentID", "tbStudentLogs", "StudentID ='" & Me.txtLoginID.Value & "'") 更改为DLookup("StudentID", "tbStudentLogs", "StudentID =" & Me.txtLoginID.Value)

    请注意,这种类型的登录不提供真正的安全性,并且以纯文本形式存储密码是一种不好的做法。此外,您的代码对 SQL 注入开放。任何输入' OR 1=1 Or 'A' = ' 作为密码的人都将通过密码检查。

    【讨论】:

    • 这发出了“运行时错误whatever the StudentID was
    • 我添加了截图
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 2012-10-25
    • 2020-11-14
    • 2023-02-16
    • 1970-01-01
    • 2016-07-03
    • 1970-01-01
    相关资源
    最近更新 更多