在 Access 2007 中,我尝试发送查询结果,但是,我不断收到错误“运行时错误‘3265’:在此集合中找不到项目。”线上出现错误:
Set qry = CurrentDb.QueryDefs(ReportQueryName)
我已经检查了字段中的拼写,并尝试使用“工具”>“引用”来确保我拥有正确的库。
这是我当前的代码:
Private Sub Command202_Click()
Dim qry As DAO.QueryDef
Dim strSQL As String
Dim ReportQueryName As String
ReportQueryName = "ReportEmail"
Set qry = CurrentDb.QueryDefs(ReportQueryName)
strSQL = "SELECT [ID], [title] FROM Cases WHERE ID = " & Me.ID
qry.SQL = strSQL
DoCmd.SendObject acSendQuery, "ReportEmail", acFormatXLSX, "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f3a323e36331f3e3b3b2d3a2c2c713c3032" rel="noreferrer noopener nofollow">[email protected]</a>", ..., , False
End Sub
最佳答案
您不能使用 QueryDefs
创建新查询 - 您必须使用 CreateQueryDef
来代替:
Private Sub Command202_Click()
Dim qry As DAO.QueryDef
Dim strSQL As String
Dim ReportQueryName As String
ReportQueryName = "ReportEmail"
strSQL = "SELECT [ID], [title] FROM Cases WHERE ID = " & Me.ID
Set qry = CurrentDb.CreateQueryDef(ReportQueryName,strSQL)
DoCmd.SendObject acSendQuery, "ReportEmail", acFormatXLSX, _
"<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ef8a828e8683af8e8b8b9d8a9c9cc18c8082" rel="noreferrer noopener nofollow">[email protected]</a>", ..., , False
End Sub
有时您的新查询不会立即显示在 Access 窗口中。
如果您愿意,可以使用:
Application.RefreshDatabaseWindow
关于ms-access - querydefs 运行时错误 3265 : item not found in this collection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31802047/