可参考一下
Public Sub 分类帐补余额_贷方余额()
'本宏为贷方余额者,若生成贷方余额,则以负号表示.
Dim varBalance As Double, strLedger As String
Dim rs1 As Recordset
Set rs1 = New ADODB.Recordset
'指定rs1的联接数据库为目前打开的数据库
rs1.ActiveConnection = CurrentProject.Connection
On Error GoTo 错误式
strLedger = InputBox("请输入你要补余额的分类帐表的名称", "基础理论")
'使用open方法打开刚生成的表 [? ?分类帐]
rs1.Open strLedger, , adOpenKeyset, adLockOptimistic, adCmdTable
'先设余额等于零
varBalance = 0
'使用Do Loop循环在表记录集合中逐笔往下计算本日余额
Do Until rs1.EOF
'rs1.Cancelupdate
rs1("余额") = rs1!贷方金额 - rs1!借方金额 + varBalance
rs1.Update
varBalance = rs1!余额
rs1.MoveNext
Loop
MsgBox "余额字段已替你补好了,你不必自己计算"
DoCmd.SelectObject acTable, strLedger, True
DoCmd.OpenTable strLedger, acViewNormal, acEdit
DoCmd.GoToControl "余额"
[此贴子已经被作者于2003-10-9 16:11:53编辑过]
|