如下:用Nz空值转0也不行
Function getBlc() As Currency
Dim rs As New ADODB.Recordset
Dim dblBlc As Double
With rs
.Open "bb", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Do While Not .EOF
.Fields("余额") = .Fields(Nz("借方金额")) - .Fields(Nz("贷方金额")) + dblBlc
dblBlc = .Fields("余额")
.Update
.MoveNext
Loop
.Close
End With
Set rs = Nothing
End Function
用下面的代码试试
Dim rs As New ADODB.Recordset
Dim dblBlc As Double
With rs
.Open "bb", CurrentProject.Connection, adOpenKeyset, adLockOptimistic
Do While Not .EOF
.Fields("余额") = .Fields("借方金额") - .Fields("贷方金额") + dblBlc
If IsNull(.Fields("余额")) = False Then
dblBlc = .Fields("余额")
.Update
End If
.MoveNext
Loop
.Close
End With
Set rs = Nothing
问题:如果“借方金额”或“贷方金额”中有空值就出错
zn不是那么用的吧?试一试:nz(.Fields("借方金额"),0)
总记录:4篇 页次:1/1 9 1 :