VBA迭代RecordSet

时间:2017-11-03 15:55:41

标签: vba ms-access access-vba ms-access-2013 recordset

我正在使用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然后停止

1 个答案:

答案 0 :(得分:2)

试试这样:

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的想法是什么?

相关问题