Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 957
Sarfaraz78615 Avatar asked Feb 16 '16 13:02

Sarfaraz78615


1 Answers

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
like image 75
Alex K. Avatar answered Sep 21 '22 07:09

Alex K.