1
j
和d
都評估相同的功能,但是當我使用If IsNull
來捕獲任何空值時,d的值未正確評估。這是什麼造成的?捕獲DSum空結果計算錯誤
Dim d As Integer
Dim j As Integer
j = DSum("Count", "qry_nihr_unique")
If IsNull(d = DSum("Count", "qry_nihr_unique")) Then
MsgBox "No records were found for the data criteria you entered"
GoTo ESub
Else
Me.un_p.Value = d
End If
Debug.Print "j = " & j
Debug.Print "d = " & d
j = 58
d = 0
更新的代碼回答
Dim d
d = DSum("Count", "qry_nihr_unique")
If IsNull(d) Then
MsgBox "No records were found for the data criteria you entered"
GoTo ESub
Else
Me.un_p.Value = d
End If
HansUp的回答後,經過下面我相信這是寫這個最有效的方式。
所以在我的代碼中,我必須測試'IsNull'然後複製該行以將值賦給d?編輯:我更新了我的代碼以反映這一點,這是最簡潔的方法嗎? –
我最好的猜測是將'd'聲明爲Variant。將'DSum()'結果賦給'd'。然後檢查'IsNull(d)'。 – HansUp