【发布时间】:2014-01-09 18:29:16
【问题描述】:
我正在尝试使用以下代码在使用 VBA 的活动工作表中导入数据,并将 Access 文件作为源。
要导入的 Access 表名为“Table01”,定义查询时出现错误消息 (Set daoQueryDef = daoDB.QueryDefs(Text)):“item not found in this collection”。
你知道问题出在哪里吗?在合成器中?
Sub Import()
Dim daoDB As DAO.Database
Dim daoQueryDef As DAO.QueryDef
Dim daoRcd As DAO.Recordset
Set daoDB = OpenDatabase("C:\Users\Desktop\Database\Database.mdb")>
Text = "SELECT * FROM `Table01`"
Set daoQueryDef = daoDB.QueryDefs(Text)
Set daoRcd = daoQueryDef.OpenRecordset
ThisWorkbook.Worksheets("Import").Range("A4").CopyFromRecordset daoRcd
End Sub
【问题讨论】: