View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default error displayed on rs.open when using late binding

Assuming your table name to be sheet1 your code looks fine. One thing to note
is that with late binding the constant values that you normally get from the
library references no longer exist. You need to either hard code the numbers
or declare the constants yourself...

Public Const adCmdTable As Long = 2
Public Const adOpenKeyset As Long = 1
Public Const adLockOptimistic As Long = 3


Sub test()
Dim cn As Object
Dim rs As Object

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=H:\Demo\Demo.accdb; Jet OLEDB:Database Password=pass; "

rs.Open "Sheet1", cn, adOpenKeyset, adLockOptimistic, adCmdTable

End Sub

When I use late binding I always get my code runnig with early binding and
then modify it to work with late binding. Compiling shows me the things I
need to fix.
--
HTH...

Jim Thomlinson


"sam" wrote:

Sorry for not posting it before. Here is my code.

Dim cn As Object
Dim rs As Object

Set cn = CreateObject("ADODB.Connection")
Set rs = CreateObject("ADODB.Recordset")

cn.Open "Provider=Microsoft.ACE.OLEDB.12.0; " & _
"Data Source=H:\Demo\Demo.accdb; Jet OLEDB:Database Password=pass; "

rs.Open "Sheet1", cn, adOpenKeyset, adLockOptimistic, adCmdTable


Thanks in advance


"Jim Thomlinson" wrote:

What is the error? How did you declare rs? Did cn successfully connect?

Post the entire routine so we can see what is going on.
--
HTH...

Jim Thomlinson


"sam" wrote:

Hi All,

I am getting an error on this line, when I used late binding.

rs.Open "Sheet1", cn, adOpenKeyset, adLockOptimistic, adCmdTable

Am I missing something or doing something wrong? I am using ADO to connect.

Thanks in advance