Thread: Late Binding
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Cindy Cindy is offline
external usenet poster
 
Posts: 10
Default Late Binding

Chip,

Yes, I was just going to write back and say I found it (I
re-read Jake's replay and he told me how to find the
numeric equivalents). Thanks!

One more question - do I need to late bind the reference
to MS Office 9.0 Object library to account for different
versions of Office? If yes, what would change in my code?

Thanks again
-----Original Message-----
Cindy,

You need to replace adOpenKeyset, adLockOptimistic, and
adCmdTable with their numeric equivalents, which are 1,

3, and 2,
respectively.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Cindy" wrote in message
...
Hi Jake,

I switched my references over as you stated but I have a
compile error on the last line of this code, at
adOpenKeyset, adLockOptimistic, adCmdTable.

I included some of my code thinking it might help.

Thanks
so much.


'Dim cn As ADODB.Connection, rs As ADODB.Recordset
Dim cn, rs As Object

Application.Cursor = xlWait

' connect to the Access database
Set cn = CreateObject("ADODB.Connection")
'Set cn = New ADODB.Connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=T:\PDA\PDA Request.mdb;"
' open a recordset for PDATracking Table
'Set rs = New ADODB.Recordset
Set rs = CreateObject("ADODB.Recordset")
rs.Open "PDATracking", cn, adOpenKeyset,
adLockOptimistic, adCmdTable

-----Original Message-----
Hi Cindy,

Not sure what feedback you already got on this, but

I'll
give it a shot.
Typically, I develop all code using Early Binding (set

a
reference, Dim
objects explicitly, use named constants from

libraries).
Once everything is
working, I modify my project to use Late Binding. To

do
this, you need to:

1) Get values of all named constants from libraries (in

your case, ADO and
Outlook). For example, if your code has adStateOpen in

it, you need to get
the actual value of this constant so that when you

remove
the reference to
ADO, your project will work. If you did not replace

the
named constant with
its value, you would get a syntax error (if you use

Option Explicit) or
unexpected results (as the constant will evaluate to

zero
when the library
reference is removed). The easiest way to get the

value
of a constant is to
print it to the Immediate Window:

?adStateOpen
1

Obviously, you'll want to do this while the reference

is still set.

2) Replace all explicit object types with Object. And

replace all Set x =
New y with a CreateObject call. So if you have:

Dim cnMain As ADODB.Connection
Dim cdEmp As ADODB.Command

Set cnMain = New ADODB.Connection
Dim cdEmp = New ADODB.Command

You would replace this with:

Dim cnMain As Object
Dim cdEmp As Object

Set cnMain = CreateObject("ADODB.Connection")
Set cdEmp = CreateObject("ADODB.Command")


That should do it. If you have any further questions

or
don't understand
something here, let us know.


--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address

unmonitored]


Cindy wrote:
I have an Excel 2000 application that uses

references to
Active X Data Objects 2.5 and Outlook 9 Object

library. I
need to instill late binding because users have

different
versions of MSOffice and this causes a problem with

the
library reference files. I did post before on this

and
received some feedback, websites, etc. but I am

confused
especially on how to "late bind" the ActiveX Data

Objects
2.5 library file. Please help if you can.

Thank you.

Cindy

.



.