Different Versions of Object Libraries

P

Phil Reynolds

I have Access 2000 and 2003 on my development machine. My client only has
Access 2000. When I develop for this client, I run Access 2000. However, my
code requires that I have the Microsoft Word Object Library and Microsoft
Outlook Object Library listed in References.

As I result, on my machine they're listed as version 11.0, and then, when I
upload the file, they show as missing. So I have to go through the steps of
removing the references and then re-adding them on the client's machine for
version 9.0. Obviously this is a bit of a pain I'd prefer to avoid.

I realize I could use late binding. But the code's already written, and I'd
prefer not to have rewrite everything -- at least not at this point.

Any ideas for how I can make this work without having to continually remove
and re-add the libraries?

Thanks.
 
S

SteveM

Since your app must work with the older libraries, why not just set a
reference to those libraries instead of v11.0 fo that project?

Steve
 
A

Albert D. Kallal

The only realistic solution here is to re-write your code for late biding.

Even a update to word or placing you software on a machine where they had a
custom install of office can break you code.

There is not really much here I can add.

You kind of being like a mechanic who asking how to avoid changing oil in
the car.

There is just not a reasonable answer here.

Either you have 100% control over how office is installed on the target
machine. Remember, even machine with the SAME version office can break if
pathnames are changed.

You have to bite the bullet. The result is code that will not break if word
is missing, upgraded, or is a different version.

It really not that hard to change to late binding. I always develop using
early binding to get the code working, and also have inti-sense during
development. Once the code is working, then you flip it over to late
binding.
 
N

Norman Yuan

If you do not use late binding, then you have to set reference to older
version of Word/Outlook object library on your developing machine (that is,
you have older Word/Outlook installed).

So, either use late binding; or (when using early binding) develop against
oldest version of automation server apps, if your app has to automate
multiple version of auotmation server apps, and hope the new version is
compatible to older version (MS Office apps are good on backward
compatibility).
 
A

AnandaSim

You have to bite the bullet. The result is code that will not break if word
is missing, upgraded, or is a different version.

I have a healthy respect for Albert's depth of knowledge and length of
experience. And all that he says applies but not all of the time.

So the safe way to develop to cover all scenarios is to do what he
says.

HOWEVER

If you are not trying to be all things to all people and only have a
specific case and a specific problem and you don't like making
adjustments to how you are doing things, run two machines, virtual
(VirtualPC or VMWare) or physical, separate your Office versions and
test what you can before delivering.

In this day and age, the cost of acquiring a second physical machine
and software is VERY LOW compared to when we started in 1990 or 1985.
The cost of running a virtual machine is even lower as long as you
have enough RAM and hard disk space.
 
P

Phil Reynolds

Thanks.

AnandaSim said:
I have a healthy respect for Albert's depth of knowledge and length of
experience. And all that he says applies but not all of the time.

So the safe way to develop to cover all scenarios is to do what he
says.

HOWEVER

If you are not trying to be all things to all people and only have a
specific case and a specific problem and you don't like making
adjustments to how you are doing things, run two machines, virtual
(VirtualPC or VMWare) or physical, separate your Office versions and
test what you can before delivering.

In this day and age, the cost of acquiring a second physical machine
and software is VERY LOW compared to when we started in 1990 or 1985.
The cost of running a virtual machine is even lower as long as you
have enough RAM and hard disk space.
 
S

SteveM

If you don't have the other versions on your machine you are probably stuck
with late binding.

Steve
 
T

Tony Toews [MVP]

Phil Reynolds said:
I realize I could use late binding. But the code's already written, and I'd
prefer not to have rewrite everything -- at least not at this point.

FWIW Late Binding should only take ten minutes or half hour per
instance of using the Word or Outlook libraries to implement. And
it's quite stable. I have many clients running an app with late
binding to Outlook and I know they don't have Outlook installed.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
A

ARC

That sounds interesting! I've seen late-binding code for open file's, and
fonts, etc., but never have seen the code for late binding on Outlook. Do
you have a link, Tony? Many thanks,

Andy
 
P

Phil Reynolds

Thanks for that. But I'm a bit confused. They don't have Outlook installed?
I assume you're saying that they can run the app on a machine without
Outlook installed, but they can't actually use the functions that use
Outlook, right?

Thanks.
 
D

Douglas J. Steele

To switch early binding code to late binding, you need to do the following:

1. Change any declarations to use Object rather than the specific object. In
other words, change

Dim objOutlook As Outlook.Application

to

Dim objOutlook As Object

2. Change how you instantiate the object from using the New keyword to using
CreateObject. In other words, change

Set objOutlook = New Outlook.Application

to

Set objOutlook = CreateObject("Outlook.Application")

3. Either replace any intrinsic constants from the formerly referenced
library with their actual values, or else define the constants in your
application. In other words, change

objOutlookRecip.Type = olTo

to either

objOutlookRecip.Type = 1

or

Const olTo As Long = 1

objOutlookRecip.Type = olTo

(this is usually the most time consuming part: making sure you've found all
the references to intrinsic constants, and that you know the actual value
for each one!)

Once you've done that, you can remove the reference under Tools |
References, and you should be okay. (The CreateObject statement will raise
an error 429 if the necessary libraries aren't present, so you have to trap
for that)

Take a look at the code in http://support.microsoft.com/?kbid=161088

Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Michael Suyama")
objOutlookRecip.Type = olCC

' Add the BCC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
objOutlookRecip.Type = olBCC

' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." &vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each ObjOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub

Late Bound, that would be:

Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
' "Rule 1": Use Object in the declarations
Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objOutlookAttach As Object

' "Rule 3": Define all instrinsic constants used from the specific object
model
Const olMailItem As Long = 0
Const olTo As Long = 1
Const olCC As Long = 2
Const olBCC As Long = 3
Const olImportanceHigh As Long = 2

' "Rule 2": Use CreateObject (which, you'll see, the original already did)
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Michael Suyama")
objOutlookRecip.Type = olCC

' Add the BCC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
objOutlookRecip.Type = olBCC

' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." &vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each ObjOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing

End Sub

or

Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Object
Dim objOutlookMsg As Object
Dim objOutlookRecip As Object
Dim objOutlookAttach As Object

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(0)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
objOutlookRecip.Type = 1

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Michael Suyama")
objOutlookRecip.Type = 2

' Add the BCC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
objOutlookRecip.Type = 3

' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "This is the body of the message." &vbCrLf & vbCrLf
.Importance = 2 'High importance

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each ObjOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next

' Should we display the message before sending?
If DisplayMsg Then
.Display
Else
.Save
.Send
End If
End With
Set objOutlook = Nothing
End Sub


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)
 
R

Rick Brandt

Phil said:
Thanks for that. But I'm a bit confused. They don't have Outlook
installed? I assume you're saying that they can run the app on a
machine without Outlook installed, but they can't actually use the
functions that use Outlook, right?

Correct. If they don't have Outlook installed with late binding your Outlook
code does not work. If they don't have Outlook installed with early binding the
whole application often does not work. The latter is obviously preferable.
 
L

lyle

I realize I could use late binding. But the code's already written, and I'd
prefer not to have rewrite everything -- at least not at this point.

This would might take thirty seconds, but not more than sixty!
You'd rather have your client screw around with misdirected
references?
 
R

Rick Brandt

Rick said:
Correct. If they don't have Outlook installed with late binding your
Outlook code does not work. If they don't have Outlook installed
with early binding the whole application often does not work. The
latter is obviously preferable.
^^^^^
former
 
T

Tony Toews [MVP]

ARC said:
That sounds interesting! I've seen late-binding code for open file's, and
fonts, etc., but never have seen the code for late binding on Outlook. Do
you have a link, Tony?

"Late Binding in Microsoft Access" page at
http://www.granite.ab.ca/access/latebinding.htm

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
T

Tony Toews [MVP]

Phil Reynolds said:
Thanks for that. But I'm a bit confused. They don't have Outlook installed?
I assume you're saying that they can run the app on a machine without
Outlook installed, but they can't actually use the functions that use
Outlook, right?

Correct. And they don't get any reference errors or other such
problems.

Also this comes in very handy when part of your network has upgraded
to a newer version of Office/Outlook and part is still on the old
version.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
 
P

Phil Reynolds

Really, sixty seconds? Maybe for extremely simple code. But I understand
your point. Thanks.
 
P

Phil Reynolds

I'd like to. But how? Even though I'm running A2000, my machine only gives
me the options to use v. 11, since I also have A2003 installed. I guess I
could set the references on the client's machine and then transfer the file
back.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top