无法使用accdb格式findVBA提供程序

与下面的代码,我得到以下错误时,无法find运行提供程序,下面的代码是从网上复制和编辑,它以前使用.mdb文件,但我试图将其更改为.accdb,因为这是我需要的格式。我试图做一个macros,当运行时复制到数据库中的某些单元格,添加到它。

我得到这个错误

run-time error "3706" Provider cannot be found it may not be properly installed 

 Const TARGET_DB = "testdb.accdb" Sub AlterOneRecord() Dim cnn As ADODB.Connection Dim rst As ADODB.Recordset Dim fld As ADODB.Field Dim MyConn Dim lngRow As Long Dim lngID As String Dim j As Long Dim sSQL As String 'determine the ID of the current record and define the SQL statement lngRow = ActiveCell.Row lngID = Cells(lngRow, 1).Value sSQL = "SELECT * FROM tblPopulation WHERE PopID = " & lngID Set cnn = New ADODB.Connection MyConn = ThisWorkbook.path & Application.PathSeparator & TARGET_DB With cnn .Provider = "Provider=Microsoft.ACE.OLEDB.12.0;" .Open MyConn End With Set rst = New ADODB.Recordset rst.CursorLocation = adUseServer rst.Open Source:=sSQL, _ ActiveConnection:=cnn, _ CursorType:=adOpenKeyset, _ LockType:=adLockOptimistic 'Load contents of modified record from Excel to Access. 'do not load the ID again. For j = 2 To 7 rst(Cells(1, j).Value) = Cells(lngRow, j).Value Next j rst.Update ' Close the connection rst.Close cnn.Close Set rst = Nothing Set cnn = Nothing End Sub 

有没有更简单的方法来做到这一点? 或者我应该尝试解决这个问题?

你缺less的是完整的连接string到你的数据库文件。

(更多关于连接string)

我给你一个粗略的想法,通常与我的代码一起工作:

在你的代码中删除这一行:

.Provider = "Provider=Microsoft.ACE.OLEDB.12.0;"

而是使用这一个:

 .ConnectionString= "Provider=Microsoft.ACE.OLEDB.12.0;" 

或者你可以使用这个:

 .Provider = "Microsoft.ACE.OLEDB.12.0" 

欲了解更多信息,你可以看到这个w3schools网站 。