MS Access:对象'_Recordset'的方法'打开'失败

时间:2012-10-25 13:34:04

标签: ms-access

我正在使用的代码:

Dim rs As New ADODB.Recordset

rs.Open "select * from QueryName", CurrentProject.Connection, adOpenDynamic, adLockReadOnly

为什么在火焰中这会返回一个开放的错误?查询本身完全没问题。

查询,顺便说一句:

SELECT DISTINCT Zone.Office, ledger.representative
FROM ledger LEFT JOIN [Zone] ON ledger.branch = Zone.app_office
WHERE (((Zone.Office)<>"" And (Zone.Office) Is Not Null) AND ((ledger.representative)<>"" And (ledger.representative) Is Not Null))

UNION SELECT DISTINCT Zone.Office, ClientList.representative
FROM ClientList LEFT JOIN [Zone] ON ClientList.branch = Zone.app_office
WHERE (((Zone.Office)<>"" And (Zone.Office) Is Not Null) AND ((ClientList.representative)<>"" And (ClientList.representative) Is Not Null))

UNION SELECT DISTINCT Zone.Office, ghs.representative
FROM ghs LEFT JOIN [Zone] ON ghs.branch = Zone.app_office
WHERE (((Zone.Office)<>"" And (Zone.Office) Is Not Null) AND ((ghs.representative)<>"" And (ghs.representative) Is Not Null))

UNION SELECT DISTINCT Zone.Office, Prospects.representative
FROM Prospects LEFT JOIN [Zone] ON Prospects.branch = Zone.app_office
WHERE (((Zone.Office)<>"" And (Zone.Office) Is Not Null) AND ((Prospects.representative)<>"" And (Prospects.representative) Is Not Null))

1 个答案:

答案 0 :(得分:3)

您需要引用Microsoft DAO x.x Object Library或2010年(或2007年?)和Microsoft Office x.x Access Database Engine Object Library

Dim rs As DAO.Recordset

Set rs = CurrentDB.OpenRecordset("NameOfquery")