简体   繁体   English

MS访问:openrecordset中的参数,并检查其是否为空

[英]MS access: parameters in openrecordset and check if it is null

I am trying something like this below 我在下面尝试这样的事情

formName = "CutomerF"
 checkboxName = "Check110"
 Dim rs As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM CheckBoxT WHERE [Form Name] = " & formName & " AND [Checkbox Name] = " & checkboxName)

After the query, I want to check if rs is null or not? 查询后,我想检查rs是否为null? If it is not null then how many elements does it have? 如果它不为null,那么它有多少个元素? How can I do this? 我怎样才能做到这一点?

You can see if a recordset has any records by using the BOF property. 您可以使用BOF属性查看记录集是否包含任何记录。 You can use the RecordCount to see how many records it has. 您可以使用RecordCount来查看它有多少条记录。 With a DAO recordset you should use the .MoveLast method first eg 对于DAO记录集,应首先使用.MoveLast方法,例如

If rs.BOF Then <Do Something>

rs.MoveLast
MsgBox "There are " & rs.RecordCount & " records."

Use the rs.RecordCount property. 使用rs.RecordCount属性。

IF rs.recordCount > 0 then 
   rs.movelast
   msg "There are " & rs.recordCount & " record(s)"
end if

In DAO when you open recordset that contains records the value of RecordCount is 1. if there are no records or it cannot determine if there are records the value is 0. In ADO the if there are no records or it cannot determine the number of records RecordCount will return -1. 在DAO中,当您打开包含记录的记录集时,RecordCount的值为1。如果没有记录,或者它无法确定是否有记录,则值为0。在ADO中,如果没有记录,或者它无法确定记录数RecordCount将返回-1。 Either way checking for greater than 0 will determine if you have records for ADO and DAO. 两种方法都可以检查是否大于0来确定您是否具有ADO和DAO的记录。

BOF and EOF used seperately will not work for ADO, you could do it, but then you have to make two checks. 单独使用的BOF和EOF不适用于ADO,您可以这样做,但随后必须进行两次检查。 if they are both true when you open the the recordset then your recordset is empty. 如果在打开记录集时它们都为true,则记录集为空。 When an ADO recordset opens with no records both BOF and EOF are set to true. 当ADO记录集没有任何记录打开时,BOF和EOF都设置为true。 https://msdn.microsoft.com/en-us/library/windows/desktop/ms675787(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/windows/desktop/ms675787(v=vs.85).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM