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

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: 93
Default Late Binding

(ADO) ActiveX Data Object 2.5 Library

Dim ADOR as Varian
Set ADOR = CreateObject("ADODB.RecordSet"

to talk to your databased, you need

Cnn={connection string, usually ODBC
Sql =P SQL statement

You should have these already

ADOR.Open Sql, Cnn ' Opens the database and returns the result of your SQ

ADO has several other object hierarchies, Connection, Stream, et

OUTLOOK

Dim OLK as Varian
Set OLK = CreateObject("Outlook.Application"

DOWNSIDE: 1. No intellisense with late bindin
2. You need to hard code predefined constants

For ADO: Download the MDAC SDK from Microsoft
For OUTLOOK: I has a reference to a Microsoft page ... can't remember right now ... will send another message if I remember

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

For Outlook, refer t

http://msdn.microsoft.com/library/de...nvironment.asp
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Late Binding

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


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Late Binding

Jake's reasoning is very sound on this. I have posted a worked example
previously (using Outlook) on this same topic. You can read it at
http://tinyurl.com/2qern

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Jake Marx" wrote in 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






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

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


.

  #7   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


.



  #8   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

.



.

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

Hi Cindy,

Cindy wrote:
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.


Please reread #1 in my original reply. <g Or use the values Chip provided.

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


Just a comment here. When you are declaring variables (whether they be
"normal" variables or object variables), you should always explicitly
declare them. In this case, cn is being declared as a Variant because you
didn't use "As Object" for it. Only rs gets declared as an Object. In this
case, it doesn't make much difference (as either Variant or Object will work
here), but doing this can cause unexpected results. That's why I typically
declare each variable on a separate line.

Other than that, your new code looks good and should work as it did when
early bound.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

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

  #10   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]



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

Thanks Jake

It works! Also, thanks for the tip on declaring
variables. I thought when you separated by a comma on the
same line they would all be declared as that type.

Have a great day
-----Original Message-----
Hi Cindy,

Cindy wrote:
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.


Please reread #1 in my original reply. <g Or use the

values Chip provided.

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


Just a comment here. When you are declaring variables

(whether they be
"normal" variables or object variables), you should

always explicitly
declare them. In this case, cn is being declared as a

Variant because you
didn't use "As Object" for it. Only rs gets declared as

an Object. In this
case, it doesn't make much difference (as either Variant

or Object will work
here), but doing this can cause unexpected results.

That's why I typically
declare each variable on a separate line.

Other than that, your new code looks good and should work

as it did when
early bound.

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address

unmonitored]

.

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

Hi Cindy,

cindy wrote:
Thanks Jake


You're welcome - glad to help out!

It works! Also, thanks for the tip on declaring
variables. I thought when you separated by a comma on the
same line they would all be declared as that type.


No problem. That's a very common misconception, BTW.

--
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 06:27 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"