If rptReduct1.State = adStateOpen Then rptReduct1.Close
rptReduct1.Open "select id from employee", dbConnect, adOpenDynamic
For intI = 0 To rptReduct1.RecordCount - 1
rptReduct1.Fields("reduct").Value = 0
rptReduct1.MoveNext
Next intI
当执行的时候,总是跳过FOR循环,调试的时候说我的总说我的rptReduct1.RecordCount的值为-1,而我的数据库id字段确实有20个值,不知道这是为什么清各位帮忙解答!100分相送!
再作修改如下:
If rptReduct1.State = adStateOpen Then rptReduct1.Close
rptReduct1.Open "select id, reduct from employee", dbConnect, adOpenDynamic, adlockoptimistic
rptReduct1.movefirst
rptReduct1.movelast
For intI = 1 To rptReduct1.RecordCount
rptReduct1.Fields("reduct") = 0 你要更新reduct字段,查询中必须有这个字段
rptReduct1.MoveNext
Next intI
如果还有问题,请在ACCESS表中查看你的ID字段是否有问题,或直接在ACCESS中用这个SQL语句查出结果来看看
If rptReduct1.State = adStateOpen Then rptReduct1.Close
rptReduct1.CursorLocation = adUseClient
rptReduct1.Open "select id from employee", dbConnect, adOpenDynamic
For intI = 0 To rptReduct1.RecordCount - 1
rptReduct1.Fields("reduct").Value = 0
rptReduct1.MoveNext
Next intI
Recordset 对象的游标类型会影响是否能够确定记录的数目。对仅向前游标,RecordCount 属性将返回 -1,对静态或键集游标返回实际计数,对动态游标取决于数据源返回 -1 或实际计数。