Solved

Outlook 12 Object Library Compatibility with Office 2003

Posted on 2009-03-31
17
685 Views
Last Modified: 2013-11-25
I have an Access Database I have been working on in Office 2007.  One component is the capability to email a report which required the Outlook 12 Object Libarry to work with the Outlook.Application function in VB.

When I tested the database on Office 2003 which many users still have, the Outlook 12 Object Library fails and causes all sorts of errors.  This is the only place I'm having a problem with reverse compatibility and hope someone has an idea of how to resolve.
0
Comment
Question by:ClearYourSix
  • 7
  • 7
  • 3
17 Comments
 
LVL 46

Expert Comment

by:tbsgadi
Comment Utility
Hi ClearYourSix,

When working with 2003 change to the Outlook 11 Object Library


Good Luck!

Gary
0
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
Hello ClearYourSix,

When I automate one Office app from another, I *always* use late binding, which usually papers over these
differences.

If you post your code we Experts can give more specific guidance.  Late binding, in a nutshell:

1) You do not set references to the external library
2) Instead of strongly typing the outside object variables, you declare them as type Object
3) You use CreateObject to instantiate the outside Application, and then use that application variable
as the "root" to tap into the external object model

Regards,

Patrick
0
 

Author Comment

by:ClearYourSix
Comment Utility
There are over 500 users.  So, the solution I need is something that involves no intervention.  When I look at VB References, I don't have the choice to select Object 11 in addition to Object 12.  See code below.  

When I deleted the reference to Outlook 12, the email capability quit working.  It only works when i have explicitly selected it in the VB Reference Library.  Code is below that originally worked with the Object Library.  
On Error GoTo Err_EMAILIndividual_Click
 

strEmailTo = Forms![Agency Business Plan]![Email_Alias]

strDate = Forms![Agency Business Plan]![Report_Date]
 

DoCmd.OpenReport "Agency Business Plan Report (Agent)", acViewPreview

DoCmd.OutputTo acOutputReport, "Agency Business Plan Report (Agent)", "Snapshot Format", "C:\TEMP\Business Plan Report.snp"
 
 

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. Substitute

   ' your names here.

   Set objOutlookRecip = .Recipients.Add(strEmailTo)

   objOutlookRecip.Type = olTo

   ' Set the Subject, Body, and Importance of the message.

   .Subject = "RESULTS: Business Plan Report - " & strDate

   .Body = "Here is your most current business plan report." & vbCrLf & vbCrLf

   .Sensitivity = olPrivate

   ' Add attachments to the message.

   If Not IsMissing(AttachmentPath) Then

   Set objOutlookAttach = .Attachments.Add("C:\TEMP\Business Plan Report.snp")

   End If

   ' Resolve each Recipient's name.

   For Each objOutlookRecip In .Recipients

         If Not objOutlookRecip.Resolve Then

         objOutlookMsg.Display

         End If

         Next

   .Send

   End With

   Set objOutlookMsg = Nothing

   Set objOutlook = Nothing

   Set objOutlookRecip = Nothing

   Set objOutlookAttach = Nothing

   

Kill ("c:\temp\business plan report.snp")

DoCmd.Close acReport, "Agency Business Plan Report (Agent)", acSaveNo

DoCmd.Maximize

Forms("Agency Business Plan").SetFocus

   
 

Exit_EMAILIndividual_Click:

    Exit Sub

Err_EMAILIndividual_Click:

    MsgBox Err.Description

      DoCmd.Close acReport, "Agency Business Plan REport (Agent)", acSaveNo

    DoCmd.Maximize

    Forms("Agency Business Plan").SetFocus

   

   End Sub

Open in new window

0
 
LVL 46

Expert Comment

by:tbsgadi
Comment Utility
You can add the 2003 Object to your PC from somebody that has 2003
0
 

Author Comment

by:ClearYourSix
Comment Utility
tbsgadi:  

How do I get it from them?  The database was originally developed in 2003 and when I switched to 2007, it automatically wiped out the Outlook 11 reference and replaced it with Outlook 12.
0
 
LVL 46

Expert Comment

by:tbsgadi
Comment Utility
You're just copying the tlb/dll file to your PC
0
 

Author Comment

by:ClearYourSix
Comment Utility
when I do that and pull it in, where it carry then to office 2003 users or at least stay active?  if so and office 2007 is later installed, will they need to reinstall tool so Outlook 12 is picked up?
0
 
LVL 46

Expert Comment

by:tbsgadi
Comment Utility
If you have the 2003 library it upgrades to 2007 - not the other way around
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:ClearYourSix
Comment Utility
I think I can make that work.  How do I ADD a reference to the library that doesn't show up in the list already?
0
 
LVL 46

Expert Comment

by:tbsgadi
Comment Utility
You press the browse button & go to the msoutl.olb file
0
 

Author Comment

by:ClearYourSix
Comment Utility
OK, give me a few hours to track down that file and test it.  Thanks.  Will get back to you tbsagdi.
0
 
LVL 46

Expert Comment

by:tbsgadi
Comment Utility
Good Luck!
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
Comment Utility
Converting to late binding, so that you need *no references* to Outlook...
On Error GoTo Err_EMAILIndividual_Click
 
strEmailTo = Forms![Agency Business Plan]![Email_Alias]
strDate = Forms![Agency Business Plan]![Report_Date]
 
DoCmd.OpenReport "Agency Business Plan Report (Agent)", acViewPreview
DoCmd.OutputTo acOutputReport, "Agency Business Plan Report (Agent)", "Snapshot Format", "C:\TEMP\Business Plan Report.snp"
 
 
Dim objOutlook As Object 'Outlook.Application
Dim objOutlookMsg As Object 'Outlook.MailItem
Dim objOutlookRecip As Object 'Outlook.Recipient
Dim objOutlookAttach As Object 'Outlook.Attachment
 
   ' Create the Outlook session.
   Set objOutlook = CreateObject("Outlook.Application")
   ' Create the message.
   Set objOutlookMsg = objOutlook.CreateItem(0)  'olMailItem
   With objOutlookMsg
   ' Add the To recipient(s) to the message. Substitute
   ' your names here.
   Set objOutlookRecip = .Recipients.Add(strEmailTo)
   objOutlookRecip.Type = 1   'olTo
   ' Set the Subject, Body, and Importance of the message.
   .Subject = "RESULTS: Business Plan Report - " & strDate
   .Body = "Here is your most current business plan report." & vbCrLf & vbCrLf
   .Sensitivity = 2   'olPrivate
   ' Add attachments to the message.
   If Not IsMissing(AttachmentPath) Then
   Set objOutlookAttach = .Attachments.Add("C:\TEMP\Business Plan Report.snp")
   End If
   ' Resolve each Recipient's name.
   For Each objOutlookRecip In .Recipients
         If Not objOutlookRecip.Resolve Then
         objOutlookMsg.Display
         End If
         Next
   .Send
   End With
   Set objOutlookMsg = Nothing
   Set objOutlook = Nothing
   Set objOutlookRecip = Nothing
   Set objOutlookAttach = Nothing
   
Kill ("c:\temp\business plan report.snp")
DoCmd.Close acReport, "Agency Business Plan Report (Agent)", acSaveNo
DoCmd.Maximize
Forms("Agency Business Plan").SetFocus
   
 
Exit_EMAILIndividual_Click:
    Exit Sub
Err_EMAILIndividual_Click:
    MsgBox Err.Description
      DoCmd.Close acReport, "Agency Business Plan REport (Agent)", acSaveNo
    DoCmd.Maximize
    Forms("Agency Business Plan").SetFocus
   
   End Sub

Open in new window

0
 

Author Comment

by:ClearYourSix
Comment Utility
tbsgadi... got the Outlook 11 file but was unable to get it to override Outlook 12 Object.  Now trying matthew's code....
0
 
LVL 46

Expert Comment

by:tbsgadi
Comment Utility
You need to first untick the outlook l2 object & then browse to the 11
0
 

Author Closing Comment

by:ClearYourSix
Comment Utility
THANK YOU for editing the code.  I had just started to research what you meant by late-binding.  The code works beautifully.
0
 
LVL 92

Expert Comment

by:Patrick Matthews
Comment Utility
ClearYourSix,

Glad to help :)

Regards,

Patrick
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Set OWA language and time zone in Exchange for individuals, all users or per database.
If you don't know how to downgrade, my instructions below should be helpful.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now