|
应该不行,但把等于号后面的查询结果复制到工作表中,可以用该表数据来更新,请参考:
Sub 更新()
Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim SQL$, i&
Application.ScreenUpdating = False
Application.DisplayAlerts = False
cnn.Open "Provider = Microsoft.Jet.Oledb.4.0;Extended Properties =Excel 8.0;Data Source =" & ThisWorkbook.FullName
SQL = "select 订单行号,sum(件数) from [出库计划$] group by 订单行号"
rs.Open SQL, cnn, adOpenKeyset, adLockOptimistic
i = rs.RecordCount + 1
With Sheets("出库计划")
.Range("A2:B" & i).Insert Shift:=xlDown
.Range("A2").CopyFromRecordset rs
SQL = "update [订单明细$] a,[出库计划$a1:b" & i & "] b set a.计划件数=b.件数 where a.订单行号=b.订单行号"
cnn.Execute SQL
.Range("A2:B" & i).Delete Shift:=xlUp
End With
Application.ScreenUpdating = True
MsgBox "更新成功。", vbInformation, "更新"
rs.Close
cnn.Close
Set rs = Nothing
Set cnn = Nothing
End Sub
|
|