Is This Recordset Empty

A recordset may be empty. To check whether your recordset has any records in it, use the Recordset object's BOF and EOF properties. The BOF property stands for "beginning of file," and EOF indicates "end of file."

If you open a Recordset object that contains no records, the BOF and EOF properties are both set to True.

If you open a Recordset object that contains at least one record, the BOF and EOF properties are False and the first record is the current record.

You can use the following conditional statement to test whether there are any records:

If rst.BOF and rst.EOF Then

MsgBox "This recordset contains no records" End If

To open a recordset based on a saved query, replace the table name with your query name.

Opening a Recordset Based on an SQL Statement

The procedure in Hands-On 13-3 demonstrates how to use the Connection object's Execute method to open a recordset based on an SQL statement that selects all the employees from the Employees table in the sample Northwind database. Only the name of the first employee is written to the Immediate window. As in the preceding example, the resulting recordset is forward-only and read-only.

0 0

Post a comment