• Cần giúp đỡ code chuyển dữ liệu từ Excel vào access !
  • Cần giúp đỡ code chuyển dữ liệu từ Excel vào access !

    DoquangLam > 05-03-14, 11:43 AM

    Mình có bảng Excel có 9 cột và nhiều dòng. Tham khảo đoạn code trên trang diễn đàn access khi thực hiện báo lỗi dòng Conn.Execute sqlR. Mong các bạn giúp đỡ. Cám ơn !

    Private Sub Command0_Click()
    Dim i As Integer
    Dim Conn As ADODB.Connection
    Set Conn = CurrentProject.Connection
    Dim WbC As Object
    Set WbC = GetObject("D:\TaiLieu.xls")
    Conn.Execute "Delete * from tblTaiLieu"
    With WbC
    With .Worksheets("Sheet1")
    For i = 2 To 6 [/align]
    sqlR = "Insert Into tblTaiLieu Values("
    sqlR = sqlR & .Cells(i, 1) & ", "
    sqlR = sqlR & .Cells(i, 2) & ", "
    sqlR = sqlR & .Cells(i, 3) & ", "
    sqlR = sqlR & "'" & 0 & "', "
    sqlR = sqlR & .Cells(i, 5) & ", "
    sqlR = sqlR & .Cells(i, 6) & ", "
    sqlR = sqlR & .Cells(i, 7) & ", "
    sqlR = sqlR & .Cells(i, 8) & ", "
    sqlR = sqlR & .Cells(i, 9) & " )"
    Conn.Execute sqlR
    Next i
    End With
    End With
    WbC.Close
    Set WbC = Nothing
    MsgBox "Done"

    End Sub
  • RE: Cần giúp đỡ code chuyển dữ liệu từ Excel vào access !

    Xuân Thanh > 05-03-14, 09:06 PM

    Bạn tham khảo tại đây http://thuthuataccess.com/forum/thread-5231.html
    Thân mến