Sarfaraz78615
Sarfaraz78615

Reputation: 124

Excel VBA ADODB Late Binding error

Actually every time I am using the Early binding code to use the ADODB Connection , However now I want to use the Late Binding Code. According to me, it seems the code is perfect but I don't the how I am getting an error Like "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

Upvotes: 5

Views: 4958

Answers (1)

Alex K.
Alex K.

Reputation: 175956

You are late binding so enums like adOpenDynamic/adLockOptimistic do not exist & default to empty variants.

Define them within your code as consts, ADOVBS.INC lists their names & values.

Const adOpenDynamic = 2
Const adLockOptimistic = 3

Upvotes: 7

Related Questions