Dim dbs As Database
Dim rst1, rst2 As DAO.Recordset
Set dbs = CurrentDb
Set rst1 = dbs.OpenRecordset("SELECT 借方, 是否勾销 FROM UF WHERE (借方<>0) ORDER BY 借方", dbOpenDynaset)
Set rst2 = dbs.OpenRecordset("SELECT 贷方, 是否勾销 FROM UF WHERE (贷方<>0) ORDER BY 贷方", dbOpenDynaset)
rst1.MoveFirst
rst2.MoveFirst
Do
Select Case (rst1!借方 - rst2!贷方)
Case Is = 0 '两边相等
rst1.Edit
rst1!是否勾销 = True '借方做勾销记号
rst1.Update
rst2.Edit
rst2!是否勾销 = True '贷方做勾销记号
rst2.Update
'两个指针都向后移动
If Not rst1.EOF Then rst1.MoveNext
If Not rst2.EOF Then rst2.MoveNext
Case Is < 0 '借方数字较小
'借方指针向后移动
If Not rst1.EOF Then rst1.MoveNext
Case Is > 0 '贷方数字较小
'贷方指针向后移动
If Not rst2.EOF Then rst2.MoveNext
End Select
Loop Until rst1.EOF Or rst2.EOF '任一记录集到达末尾则不再循环
Set rst1 = Nothing
Set rst2 = Nothing
'dbs.Close
End Sub 作者: xinbao 时间: 2002-5-11 08:08
妙,高手就是高手,程序就是招牌,难怪站长对你推崇备至!作者: MsAccess 时间: 2002-5-12 17:33
AlexLiu 的思维不错。多谢。
还有一点本人上次未说清,就是时间靠近者优先勾销。
再就是频繁判断是否到表的最后也会影响执行的速度。