Applies To Dynamic-Type Recordset object, Dynaset-Type Recordset object, Forward-Only–Type Recordset object, Recordset object, Snapshot-Type Recordset object, Table-Type Recordset object.
Description
Return Values
MoveFirst, MoveLast | MovePrevious, Move < 0 | Move 0 | MoveNext, Move > 0 | |
BOF=True, EOF=False | Allowed | Error | Error | Allowed |
BOF=False, EOF=True | Allowed | Allowed | Error | Error |
Both True | Error | Error | Error | Error |
Both False | Allowed | Allowed | Allowed | Allowed |
BOF | EOF | |
MoveFirst, MoveLast | True | True |
Move 0 | No change | No change |
MovePrevious, Move < 0 | True | No change |
MoveNext, Move > 0 | No change | True |
See Also MoveFirst, MoveLast, MoveNext, MovePrevious methods.
Example This example demonstrates how the BOF and EOF properties let the user move forward and backward through a Recordset.Sub BOFX()
Dim dbsNorthwind As Database
Dim rstCategories As Recordset
Dim strMessage As String
Set dbsNorthwind = OpenDatabase("Northwind.mdb")
Set rstCategories = _
dbsNorthwind.OpenRecordset("Categories", dbOpenSnapshot)
With rstCategories
' Populate Recordset.
.MoveLast
.MoveFirst
Do While True
' Display current record information and get user
' input.
strMessage = "Category: " & !CategoryName & _
vbCr & "(record " & (.AbsolutePosition + 1) & _
" of " & .RecordCount & ")" & vbCr & vbCr & _
"Enter 1 to go forward, 2 to go backward:"
' Move forward or backward and trap for BOF or EOF.
Select Case InputBox(strMessage)
Case 1
.MoveNext
If .EOF Then
MsgBox _
"End of the file!" & vbCr & _
"Pointer being moved to last record."
.MoveLast
End If
Case 2
.MovePrevious
If .BOF Then
MsgBox _
"Beginning of the file!" & vbCr & _
"Pointer being moved to first record."
.MoveFirst
End If
Case Else
Exit Do
End Select
Loop
.Close
End With
dbsNorthwind.Close
End Sub
Example (Microsoft Access)
The following example uses the EOF property of a Recordset object to move the current record pointer past the last record in the Recordset object, then uses the BOF property to move the current record pointer to before the first record in the Recordset object.
Sub EndsOfFile()
Dim dbs As Database, rst As Recordset
' Return reference to current database.
Set dbs = CurrentDb
' Open recordset on Orders table.
Set rst = dbs.OpenRecordset("Orders")
' Do until end of file.
Do Until rst.EOF
' Move to next record.
rst.MoveNext
.
.
.
Loop
' Move to last record to set a current record.
rst.MoveLast
' Do until beginning of file.
Do Until rst.BOF
rst.MovePrevious
.
.
.
Loop
rst.Close
Set dbs = Nothing
End Sub