如果用ado处理,则可以用两个循环处理:
Function UpdateJsYs()
Dim rst1 As new ADODB.Recordset,rst2 As new ADODB.Recordset
dim ssql as string
dim i as long,j as long
dim cnt as long
ssql="select distinct 档号 from 表2"
rst1.Open ssql, CurrentProject.Connection, 1, 3
for i=1 to rst1.RecordCount '按档号循环
ssql="select * from 表2 where 档号='" & rst1!档号.value & "' order by 序号"
rst2.Open ssql, CurrentProject.Connection, 1, 3
cnt=0
for j=1 to rst2.recordcount
if j=1 then
rst2!页次.value=1
else
rst2!页次.value=cnt
end if
rst2!文件级档号.value=rst2!档号 & "." & Format(rst2!页次, "000")
rst2.update
'用cnt保存本条记录的页次与页数之和,准备赋值给下一条记录的页次
'也可将写为:cnt=cnt+rst2!页数.value,同时将rst2!页次.value=cnt改为rst2!页次.value=cnt+1
cnt=rst2!页次.value+rst2!页数.value
rst2.movenext
next
rst2.close
rst1.movenext
next
set rst2=nothing
rst1.close:set rst1=nothing
End Function