我在 Access 2010 db 中有一个表,其列名与 excel 表中的列名相同。在将数据从宏启用的 excel 2010 表中泵入其中之前,我必须删除 Access 表数据内容。现在我正在尝试查看/测试是否可以将我的 excel 数据泵入 Access 中的空表。一旦我得到这个工作,我可以得到'在转储excel数据之前删除内容'的工作。
这是我的 excel vba 宏代码:
Sub ADOFromExcelToAccess()
'exports data from the active worksheet to a table in an Access database
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
' connect to the Access database
Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=C:\Users\shress2\Documents\TSS_Certification\TSS_Certification.accdb;"
' open a recordset
Set rs = New ADODB.Recordset
rs.Open "t_certification_051512", cn, adOpenKeyset, adLockOptimistic, adCmdTable
' all records in a table
r = 2 ' the start row in the worksheet
Do While Len(Range("A" & r).Formula) > 0
' repeat until first empty cell in column A
With rs
.AddNew ' create a new record
' add values to each field in the record
.Fields("Role") = Range("A" & r).Value
.Fields("Geo Rank") = Range("B" & r).Value
.Fields("Geo") = Range("C" & r).Value
' add more fields if necessary...
.Update ' stores the new record
End With
r = r + 1 ' next row
Loop
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
结束子
我添加了 Tools--> References 并选择了 Microsoft ActiveX Data Objects 6.0 Object Library。
我收到运行时错误'-2147467259(80004005)':无法识别的数据库格式'C:\Users\shress2\Documents\TSS_Certification\TSS_Certification.accdb
有什么理由吗?我该如何解决?谢谢。