|
首先,你要保证"资金流量表临时"是按照姓名排列的。Public Sub 存款余额补填()
Dim db As ADODB.Connection, varBalance As Double
Dim rs As ADODB.Recordset
Dim strName as string
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
rs.ActiveConnection = CurrentProject.Connection
On Error GoTo 错误式
rs.Open "资金流量表临时", , adOpenKeyset, adLockOptimistic, adCmdTable
varBalance = 0
strName = rs!单位帐户
Do Until rs.EOF
rs.CancelUpdate
if strName = rs!单位帐户 then
rs("余额") = Nz(rs!收入, 0) - Nz(rs!支出, 0) + varBalance
else
rs("余额") = Nz(rs!收入, 0) - Nz(rs!支出, 0)
strName = rs!单位帐户
end if
varBalance = rs!余额
rs.Update
rs.MoveNext
Loop
rs.Close
Exit Sub
错误式:
If Err.Number <> 0 Then
MsgBox "错误讯息:" & Err.Description & "错误代码" & Err.Number
Else
MsgBox "没有错误发生,Err代码是:" & Err.Number
End If
Exit Sub
End Sub
未经测试,可能会有点问题。 |
|