Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Late Binding

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


.



  #2   Report Post  
Posted to microsoft.public.excel.programming
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

.



.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Late Binding

Hi Cindy,

cindy wrote:
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!


You can ignore my second post, then.... <g

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?


No - that reference is put in there automatically by Excel. It will change
as needed when users with other versions open the workbook.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
VB Extensibility library and "late binding" Dennis Excel Discussion (Misc queries) 0 March 30th 05 10:51 PM
EARLY binding or LATE binding ? jason Excel Programming 6 February 26th 04 04:57 PM
DAO Late Binding? Sharqua Excel Programming 2 January 4th 04 02:05 AM
Early vs Late Binding - Word John Wilson Excel Programming 6 November 13th 03 03:21 PM
DAO objects with late binding in Excel? Chris Excel Programming 0 August 21st 03 07:28 PM


All times are GMT +1. The time now is 03:58 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"