如何测试记录集是否为空?
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"
我正在根据 select 语句打开几个记录集。如果没有记录,IsNull会返回true吗?
我会检查“文件结束”标志:
If temp_rst1.EOF Or temp_rst2.EOF Then MsgBox "null"
RecordCount 是您想要使用的。
If Not temp_rst1.RecordCount > 0 ...
如果
temp_rst1.BOF
和 temp_rst1.EOF
则记录集为空。对于空记录集、链接记录集或本地记录集始终如此。
一个简单的方法就是这样写:
Dim rs As Object
Set rs = Me.Recordset.Clone
If Me.Recordset.RecordCount = 0 then 'checks for number of records
msgbox "There is no records"
End if
如果不是 temp_rst1 则什么都不是...
在这里,我使用 MS Access 2016,并使用以下命令检查记录集字段是否为空:
If (RecordSt.Fields("field_name").Value) Then
' do what you want if there is returned data
Else
' do what you want if there isn't any data returned by the select