The BOF and EOF Properties

These properties indicate whether the record pointer of the Recordset object is positioned before the first record in the recordset (BOF, or beginning of file) or after the last record in the recordset (EOF, or end of file). If the recordset is empty, both BOF and EOF will be True. The following code example demonstrates using these properties to determine if there is data in a recordset:

If Not rsData.EOF Then

' The Recordset contains data.

Else

' The Recordset is empty. End If

Note that there is a difference between an empty recordset and a closed recordset. If you execute a query that returns no data, ADO will present you with a perfectly valid open recordset, but one that contains no data. Therefore, you should always verify that a recordset contains data using the previous method prior to any attempt to access that data. Attempting to access data from an empty recordset will cause a run-time error.

0 0

Post a comment