我有以下vba代码来检查已经在子窗体上选择了产品。然后提醒用户。
Private Sub ProdId_Combo_BeforeUpdate(Cancel As Integer)
Dim icount As Long
icount = Nz(DCount("[ProdID]", "ProdRestockDetails", "[ProdID]=" & Me.ProdID & " AND RestockID=" & Me.RestockID, 0))
If icount <> 0 Then
MsgBox "this item has already been selected."
Cancel = True
Undo
End If
End Sub
但它会引发错误。 有人可以帮我正确设置吗?
答案 0 :(得分:0)
看起来您的Dcount和Nz功能未正确结束。你能试试吗?使用DCount函数时,您不需要Nz包装器,因为如果未找到该值,则应返回零。
Private Sub ProdId_Combo_BeforeUpdate(Cancel As Integer)
Dim icount As Long
icount = Nz(DCount("[ProdID]", "ProdRestockDetails", "[ProdID]=" & Me.ProdID & " AND RestockID=" & Me.RestockID), 0)
If icount <> 0 Then
MsgBox "this item has already been selected."
Cancel = True
Undo
End If
End Sub