Name

recordset.EOF[= setting]

Synopsis

True if the current record position is after the last record in the recordset. The following code uses the EOF property to test for the end of the recordset, adding names from the Employees table in the Northwind Traders sample database to the first column of the current worksheet:

recordset.MoveFirst Dim strDbPath As String
Dim db As DAO.Database
Dim rs As DAO.Recordset
 
strDbPath = "C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb"
Set db = OpenDatabase(strDbPath)
Set rs = db.OpenRecordset("Employees")
 
rs.MoveFirst
intIdx = 1
Do Until rs.EOF
    strName = rs!FirstName & " " & rs!LastName
    ActiveSheet.Cells(intIdx, 1) = strName
    rs.MoveNext
    intIdx = intIdx + 1
Loop

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.