演员王瑄:ADO实现EXCEL与ACCESS数据存储,提示出错(页 1)

来源:百度文库 编辑:中财网 时间:2024/05/05 06:38:40
Sub ADO_INPUT() '将记录导入到excel中
Dim RS1 As Recordset
Dim DB1 As Database
Dim col As Integer
Dim I As Integer
'On Error GoTo 1000
col = Sheet2.Range("A65535").End(xlUp).Row
Set DB1 = OpenDatabase(ThisWorkbook.Path & "\" & "backdatabase.accdb ")
Set RS1 = DB1.OpenRecordset(Name:="aa", Type:=dbOpenDynaset)
dim m as integer
For I = 7 To col
With RS1
   .AddNew
    for m = 1 to 17
        '如果你的数据库中的数据跟excel都是按照顺序来的,则用一个循环足以!
        .fields(m)=sheet2.cells(i,m)
    next
    .Update
    End With
Next I
RS1.Close
'1000: MsgBox "找不到符合条件的记录", 1 + 64, "系统提示"
End Sub