我在表单上有一些VBA代码,可以查询查询中的错误总数。
Private Sub cboProjectID_Change()
Dim VarTotalErrors As Variant
VarTotalErrors = DLookup("[total errors]", "[Project_Total_Errors_Query]", "[Project_ID] = " & VarComboKey)
Me.txttotalerrors = VarTotalErrors
End Sub
当total_errors为null时,我需要添加到此VBA代码以自动填充零值的条件是什么?
答案 0 :(得分:2)
您可以将DLookup
值提供给Nz
并将结果直接分配到文本框,这样可以简化代码。
Private Sub cboProjectID_Change()
Me.txttotalerrors = Nz(DLookup("[total errors]", _
"[Project_Total_Errors_Query]", _
"[Project_ID] = " & VarComboKey), 0)
End Sub
答案 1 :(得分:1)
Private Sub cboProjectID_Change()
Dim VarTotalErrors As Variant
VarTotalErrors = DLookup("[total errors]", "[Project_Total_Errors_Query]", "[Project_ID] = " & VarComboKey)
If Nz(VarTotalErrors) = 0 Then
Me.txttotalerrors = "0"
else
Me.txttotalerrors = VarTotalErrors
end if
End Sub