1

我正在使用的代码:

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))
4

1 回答 1

3

您将需要参考Microsoft DAO x.x Object Library2010 年(或 2007 年?)或之后的Microsoft Office x.x Access Database Engine Object Library

Dim rs As DAO.Recordset

Set rs = CurrentDB.OpenRecordset("NameOfquery")
于 2012-10-25T14:35:11.933 回答