Access 2016 VBA Sub-RecordsetClone上的“此集合中未找到项目”错误

时间:2018-10-22 12:59:32

标签: vba ms-access-2016

我有一个表格,显示以下查询的结果:

SELECT Database.Contact_ID, Database.[Full Name], Database.[Job Title], 
Institution.Institution, Database.Email, Database.[Email 2], Database.[Work 
phone], Database.[Work phone 2], Database.Mobile, Database.Notes, Database. 
[Date created], [Keyword Junction].Keywords, Database.[Record Type]

FROM Institution INNER JOIN (Keywords INNER JOIN ([Database] INNER JOIN 
[Keyword Junction] ON Database.[Contact_ID] = [Keyword Junction].Contact_ID) 
ON Keywords.Keyword_ID = [Keyword Junction].Keywords.Value) ON Institution.ID 
= Database.InstitutionLookup

WHERE (((Keywords.Keyword) Like [Enter Keyword] & "*"))

ORDER BY Database.[Record Type] DESC , Database.Surname;

在我创建了一个链接到按钮的子窗体的表单上,这是VBA:

Private Sub Send_Email_Click()    
Dim rs As DAO.Recordset
Dim bcc As String
Dim Name As String
Call fOSUserName
Name = LCase(fOSUserName) & "insertdomainhere"

     Set rs = Forms!KeywordSearch.RecordsetClone
      If rs.RecordCount > 0 Then
          rs.MoveFirst
          Do
              If Not IsNull(rs!Email) Then
                  bcc = bcc & rs!Email & ";"
                  rs.MoveNext
             Else
                  rs.MoveNext                            
               End If                   
         Loop Until rs.EOFa                          
    DoCmd.SendObject acSendNoObject, , , Name, , bcc, , , True

    End If
    Set rs = Nothing   
    End Sub

当我单击按钮时,出现“错误3265:在集合中找不到项目”。调试器显示问题出在“ If Not IsNull(rs!Email)然后”行上,显然“电子邮件”字段不在记录集中。我能想到的唯一问题是查询正在使用具有多值字段的表。

赞赏有关如何解决此错误的任何建议。

1 个答案:

答案 0 :(得分:0)

我认为错误在于行Set rs = Forms!KeywordSearch.RecordsetClone

我假设keywordSearch不是子表单,所以它不能具有(recordsetclone)属性,该属性是form属性,即使那样,即使KeywordSearch确实是某种子表单,也应该将其设置为rs = Forms!KeywordSearch.form .RecordsetClone