MS Access DCount验证

问题描述 投票:0回答:2

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

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或其他方法的帮助建议吗?

ms-access ms-access-2013 ms-access-2016
2个回答
0
投票

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

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

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


0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.