|
这里也有个计算余额的函数,使用时直接套用就可以了。
'示例 Call 计算余额("财务明细帐", "收入", "支出", "余额")
Public Function 计算余额(str表 As String, str借方 As String, str贷方 As String, str余额 As String) As Boolean
On Error GoTo Err_计算余额
Dim con As New ADODB.Connection
Dim Rs As New ADODB.Recordset
Dim varBalance As Double
Set con = CurrentProject.Connection
Rs.Open str表, con, adOpenKeyset, adLockOptimistic, adCmdTable
varBalance = 0
Do Until Rs.EOF
Rs.CancelUpdate
Rs(str余额) = Nz(Rs(str借方), 0) - Nz(Rs(str贷方), 0) + varBalance
Rs.Update
varBalance = Rs(str余额)
Rs.MoveNext
Loop
计算余额 = True
Rs.Close
Set Rs = Nothing
Set con = Nothing
Exit_计算余额:
Exit Function
Err_计算余额:
计算余额 = False
Set Rs = Nothing
Set con = Nothing
MsgBox Err.Description
Resume Exit_计算余额
End Function
|
|