Excel VBA ADODB 后期绑定错误

Excel VBA ADODB Late Binding error

其实我每次都是用Early binding code来使用ADODB Connection,但是现在我想用Late Binding Code。 根据我的说法,代码似乎很完美,但我不知道我是如何收到错误的 "Argument are of the wrong type, are out of acceptable range, or in conflict with one another."

Sub Test()
Dim cn As Object
Dim rs As Object
Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.RecordSet")
cn.Open "Provider=Microsoft.JET.Oledb.4.0;Data Source=Y:\Operational Non Sensitive\Avon UK\UK Voice Productivity\UK AHT Report_.mdb"
rs.Open "Table1", cn, adOpenDynamic, adLockOptimistic
rs.Close
cn.Close
Set rs = Nothing
Set cn = Nothing
End Sub

您是后期绑定,因此像 adOpenDynamic/adLockOptimistic 这样的枚举不存在并且默认为空变体。

在您的代码中将它们定义为常量,ADOVBS.INC 列出它们的名称和值。

Const adOpenDynamic = 2
Const adLockOptimistic = 3