我使用VBA来迭代一个记录集,当我使用RecordCount特性时,它返回8(这是准确的)--但是当我在每次传递时使用Debug.Print输出变量时,只处理前3个变量。
为什么这个语法会停止呢?
Set rs = Db.OpenRecordset("Select statement here)", dbOpenDynaset)
Debug.Print rs.RecordCount
'This prints 8
With rs
If Not .EOF And Not .BOF Then
.MoveLast
.MoveFirst
Do While Not .EOF
fakca = .Fields(0).Value
Debug.Print fakca
'only prints the first 3 in the table?
.MoveNext
Loop
End If
End With.RecordCount将打印1,2,3101,4,5,6,7,9,但Debug.Print fakca只打印1,2,3101并停止。
发布于 2017-11-03 16:31:28
就像这样:
With rs
If Not .EOF Then
.MoveFirst
Do While Not .EOF
fakca = .Fields(0).Value
Debug.Print fakca
.MoveNext
Loop
End If
End With我认为这个问题来自于这样的用法:
If Not .EOF And Not .BOF Then
.MoveLast
.MoveFirst因此,我避免了这种情况。使用.BOF的想法是什么?
https://stackoverflow.com/questions/47099792
复制相似问题