|
暮烟批 发表于 2015-1-21 18:53
附件上传,您看一下能实现吗,谢谢。 - Sub 根据序号更新记录()
- Dim cnn As New ADODB.Connection
- Dim strTemp As String
- Dim SQL As String
- Dim arr As Variant
- Dim i As Integer
- cnn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & ThisWorkbook.Path & "\肯纳金属模具查询系统-.accdb"
- arr = Intersect(Range("A1").CurrentRegion, Rows(1))
- For i = 2 To UBound(arr, 2)
- strTemp = strTemp & ",A.[" & arr(1, i) & "]=B.[" & arr(1, i) & "]"
- Next
- SQL = "UPDATE 模具库 A,[Excel 12.0;Imex=0;Database=" & ThisWorkbook.FullName & ";].[" & ActiveSheet.Name & "$" _
- & Range("A1").CurrentRegion.Address(0, 0) & "] B SET " & Mid(strTemp, 2) & " WHERE A.序号=B.序号"
- cnn.Execute SQL
- MsgBox "数据修改成功。", vbInformation, "数据修改"
- cnn.Close
- Set cnn = Nothing
- End Sub
复制代码 |
|