Excel VBA ADODB Late Binding error
Asked Answered
R

1

5

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
Requirement answered 16/2, 2016 at 13:35 Comment(1)
getting the error while opening the the recordsetRequirement
P
7

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
Ptarmigan answered 16/2, 2016 at 13:45 Comment(1)
Thanks Alex, Your Code helps me a Lot.Requirement

© 2022 - 2024 — McMap. All rights reserved.