nghiapv084
Thành viên mới

- Tham gia
- 24/7/14
- Bài viết
- 46
- Được thích
- 2
Tgui Các Anh ,
nhờ các anh chỉnh sửa giúp em đoạn code sau để có thể update dử liệu từ excell sang access.
Sub Update()
Dim cnn, rst As Object, lsSQL As String
Dim arr
Dim arr1
arr = Sheet15.Range("d25:d27")
arr1 = Sheets("FBKDV1").[b25:b27].Value
Set cnn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")
With cnn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=" & ThisWorkbook.Path & "\DATADV.accdb"
.Open
End With
If Sheet15.Range("b25") Like "" Then
MsgBox (" update khong de trong "), vbInformation, "Thông Báo"
Exit Sub
End If
For J = 1 To UBound(arr1)
For I = 1 To UBound(arr)
Value2 = arr1(J, 1)
Value = arr(i, 1)
lsSQL = " update tb_dulieu set [SOHD] = " & Value & " where tb_nhapid LIKE " & Value2 & ""
rst.Open lsSQL, cnn
Next
'MsgBox (" update ok "), vbInformation, "Thông Báo"
Next
Set rst = Nothing
cnn.Close
Set cnn = Nothing
End
End Sub
nhờ các anh chỉnh sửa giúp em đoạn code sau để có thể update dử liệu từ excell sang access.
Sub Update()
Dim cnn, rst As Object, lsSQL As String
Dim arr
Dim arr1
arr = Sheet15.Range("d25:d27")
arr1 = Sheets("FBKDV1").[b25:b27].Value
Set cnn = CreateObject("ADODB.Connection")
Set rst = CreateObject("ADODB.Recordset")
With cnn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = "Data Source=" & ThisWorkbook.Path & "\DATADV.accdb"
.Open
End With
If Sheet15.Range("b25") Like "" Then
MsgBox (" update khong de trong "), vbInformation, "Thông Báo"
Exit Sub
End If
For J = 1 To UBound(arr1)
For I = 1 To UBound(arr)
Value2 = arr1(J, 1)
Value = arr(i, 1)
lsSQL = " update tb_dulieu set [SOHD] = " & Value & " where tb_nhapid LIKE " & Value2 & ""
rst.Open lsSQL, cnn
Next
'MsgBox (" update ok "), vbInformation, "Thông Báo"
Next
Set rst = Nothing
cnn.Close
Set cnn = Nothing
End
End Sub