Search code examples
vbams-accessrecordset

How do I test if a Recordset is empty?


How do I test if a Recordset is empty?

Dim temp_rst1 As Recordset
Dim temp_rst2 As Recordset
            
Set temp_rst1 = db.OpenRecordset("SELECT * FROM ORDER_DATA WHERE SKUS_ORDERED = '" & curSKU1 & "' AND [ORDER] = " & curOrder)
Set temp_rst2 = db.OpenRecordset("SELECT * FROM ORDER_DATA WHERE SKUS_ORDERED = '" & curSKU2 & "' AND [ORDER] = " & curOrder)
            
If IsNull(temp_rst1) Or IsNull(temp_rst2) Then MsgBox "null"

I'm opening up a couple of Recordsets based on a select statement. If there are no records, will IsNull return true?


Solution

  • I would check the "End of File" flag:

    If temp_rst1.EOF Or temp_rst2.EOF Then MsgBox "null"