【发布时间】:2020-07-13 19:23:54
【问题描述】:
我知道,对于这个问题,有很多答案应该是微不足道的,但我没有找到正确的答案。这是我的问题: 我使用以下 select 语句打开一个记录集:
SELECT twinecellar.produktnavn, twinecellar.land,
twinecellar.produkttype, twinecellar.år,
twinecellar.antall, twinecellar.poeng,
twinecellar.Picture, twinecellar.KR,
twinecellar.Poengsum, twinecellar.Sum
FROM twinecellar
WHERE (((twinecellar.land)=forms!fmainview!list13)
And ((twinecellar.produkttype)=forms!fmainview!list15))
ORDER BY twinecellar.poeng;
在即时窗口中,我看到列表 13 包含“法国”,列表 15 包含“红色” 当我使用此语句创建一个新查询时,它正在工作,但是,在 rst.Open gsStrQuery 上我收到此错误。 gsStrQuery 包含选择字符串。
代码如下:
Dim conn As ADODB.Connection
Dim rst As ADODB.Recordset
Set conn = CurrentProject.Connection
Set rst = New ADODB.Recordset
rst.CursorType = adOpenDynamic
rst.ActiveConnection = conn
rst.Open gsStrQuery
有人对这个问题有好的想法吗?
【问题讨论】:
-
当您在即时窗口
?gsStrQuery中写入时,您会得到什么? -
与此处相同的原因:stackoverflow.com/a/32118340/3820271 - 但该答案为 DAO 提供了解决方案。您需要设置参数。
-
请在 VBA 中显示对您的问题至关重要的 gsStrQuery 的分配。
-
写 ?gsStrQuery,我明白了
-
写作 ?gsStrQuery,我得到 SELECT twinecellar.produktnavn, twinecellar.land, twinecellar.produkttype, twinecellar.år, twinecellar.antall, twinecellar.poeng, twinecellar.Picture, twinecellar.KR, twinecellar.Poengsum , twinecellar.Sum FROM twinecellar WHERE (((twinecellar.produkttype)=[forms]![fmainview]![list15])) 按 twinecellar.land 订购;