MS Access DCount验证

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MS Access DCount验证相关的知识,希望对你有一定的参考价值。

我想在文本框中输入时验证产品代码。我似乎无法找到一种方法来抛出一个消息框,说没有输入任何内容。

Me.txt_Product = UCase(Me.txt_Product)

If Not IsNull(upProd) Then
    If DCount("Validation_Test", "Validation_Testing_Table", "[Validation_Test] = '" & UCase(Me.txt_Product) & "'") >= 1 Then
        MsgBox "User Name Found!"
    ElseIf Me.txt_Product.Value = "" Then
        MsgBox "You Did Not Enter a Product Code!"
    Else
        MsgBox "User Name Not Found!"
    End If
End If

有关DCount或其他方法的帮助建议吗?

答案

我怀疑textbox是Null并且测试空字符串失败。处理Null或空字符串的可能性:

ElseIf Me.txt_Product.Value & "" = "" Then

将Null与“”(空字符串)连接返回空字符串。

另一答案

您可以创建更好的逻辑流程:

Me!txt_Product.Value = UCase(Me!txt_Product.Value)

If Not IsNull(upProd) Then
    If Nz(Me!txt_Product.Value) = "" Then
        MsgBox "You Did Not Enter a Product Code!"
    Else
        If IsNull(DLookup("Validation_Test", "Validation_Testing_Table", "[Validation_Test] = '" & Me!txt_Product.Value & "'")) Then
           MsgBox "User Name Not Found!"
        Else
           MsgBox "User Name Found!"
        End If
    End If
End If

并小心所有这些惊叹号。用户将在不被大喊的情况下理解该消息。

以上是关于MS Access DCount验证的主要内容,如果未能解决你的问题,请参考以下文章