我有這個用于條件格式的基本 VBA 腳本。它檢查重復值。但是這個函式也會為空單元格回傳 True 。如何調整此公式,使其僅計算非空值?
是否可以使用 Dlookup 函式來比較me.txt_Number_1欄位中[Number_1]是否已存在我新輸入的數字?
Private Sub Form_Current()
If Nz(DCount("*", "[qry_DataEntry]", "[Number_1] = '" & Me.txt_Number_1 & "'"), 0) = 1 Then
Me.txt_Duplicate.Visible = False
Else
Me.txt_Duplicate.Visible = True
End If
End Sub
uj5u.com熱心網友回復:
如果在查詢中嘗試使用 IsNull() 會怎樣?替換一個欄位或使用帶括號的多個。像這樣的東西:
With Me
If DCount("*", "qry_DataEntry", "Number_1 = '" & .txt_Number_1 & "' AND NOT IsNull(Number_1)") Then
.txt_Duplicate.Visible = False
Else
.txt_Duplicate.Visible = True
End If
End With
uj5u.com熱心網友回復:
要計算非空值,請使用;
DCount("[Number_1]", "[qry_DataEntry]", "[Number_1] <> Null")
要檢查最近輸入的號碼,請使用;
DLookup("[Number_1]", "[qry_DataEntry]", "[Number_1] = " & Me.txt_Number_1)
Number_1 是數字嗎?根據此示例設定搜索條件時,數字欄位不需要用引號括起來。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/359961.html
上一篇:顯示文章的類別名稱
下一篇:MSAccess和存盤程序
