|
adodb update+select 语句提示 “操作必须使用一个可操作的查询”,网上说是access 不支持update带select子查询,不只如何解决?还请大牛帮忙看一下:
以下是代码,代码的目的是根据子查询Sql1的结果,更新[20210604$]的“总库存”字段:
Sub kucun()
Dim cnn As Object, rst As Object
Dim Mypath$, Datapath$, Str_cnn$, Sql1$, Sql2$
Set cnn = CreateObject("adodb.connection")
Set rst = CreateObject("adodb.recordset")
'绑定ADO
Mypath = ThisWorkbook.FullName
Datapath = ThisWorkbook.Path & "\库存.xlsx"
Str_cnn = "Provider=Microsoft.ACE.OLEDB.12.0;Extended Properties=Excel 12.0;Data Source=" & Mypath
cnn.Open = Str_cnn
'建立数据连接
Sql1 = "select 物料代码, sum(基本单位数量) as 总库存 from [Excel 12.0;DATABASE=" & Datapath & "].[即时库存$] group by 物料代码"
Sql2 = "update [20210604$]a Left Join (" & Sql1 & ")b on a.料号=b.物料代码 set a.总库存=b.总库存"
cnn.Execute (Sql2)
cnn.Close
Set cnn = Nothing
End Sub |
|