Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

outlook 2013 ms access

Posted on 2014-11-10
23
Medium Priority
?
134 Views
Last Modified: 2014-11-11
I was using the following code within MS Access 2003 (XP) to pipe contact data into Outlook.  Worked great with Outlook 2003 and Outlook XP. It does not work with Outlook 2013.  Is there an easy fix for this, or is it more involved?

Code:
==================================
 Set OlkApp = New Outlook.Application
   With OlkApp
      Set olkCon = .CreateItem(Outlook.OlItemType.olContactItem)
      With olkCon

.BusinessTelephoneNumber = strBusinessTelephonenumber
.HomeTelephonenumber = strHomeTelephonenumber
.MobileTelephoneNumber = strMobileTelephonenumber
.BusinessFaxNumber = strBusinessFaxNumber
.Email1Address = strEmail1Address
.JobTitle = strJobTitle
.CompanyName = strCompanyName
.FirstName = strFirstname
.LastName = strLastname
.BusinessAddressStreet = strBusinessAddressStreet
.BusinessAddressCity = strBusinessAddressCity
.BusinessAddressState = strBusinessAddressState
.BusinessAddressPostalCode = strBusinessAddressPostalCode

                Forms![Main F]![MainSub].Form![Command178].SetFocus
                Forms![Main F]![MainSub].Form![Contacts_Corr_Pick].Visible = False
                DoCmd.Requery



         olkCon.Save
      End With
   End With
   
   ' Clean up.
   Set OlkApp = Nothing
   Set olkCon = Nothing
=============================================

Fails here:  "   Set OlkApp = New Outlook.Application"
0
Comment
Question by:hgj1357
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 9
23 Comments
 
LVL 85
ID: 40433543
Are you sure Outlook is installed on the machine? If I'm not mistaken, I believe Outlook 2013/O365 can be entirely hosted "in the cloud", which would mean nothing is installed on the local machine.
0
 
LVL 58
ID: 40433556
A little more detail on what doesn't work would be helpful.

But the short answer is no, it should be workable.

Jim.
0
 
LVL 2

Author Comment

by:hgj1357
ID: 40433561
Think so. i have an Outlook.exe in the "C:\Program Files\Microsoft Office 15\root\office15" folder and I have OST files in the \..\Local Settings\application data\microsoft\Outlook folder
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 2

Author Comment

by:hgj1357
ID: 40433563
BTW. I'm still using Access 2003 NOT 2013
0
 
LVL 2

Author Comment

by:hgj1357
ID: 40433568
I get the following error show in attachment 001.  002 shows my current references.
001.jpg
002.jpg
0
 
LVL 58
ID: 40433645
Your using early binding and specifying Outlook XP.  You need to update the reference or switch to late binding.

Jim.
0
 
LVL 2

Author Comment

by:hgj1357
ID: 40433667
I don't know what late binding is. How would I update the reference?
0
 
LVL 58
ID: 40433696
Late binding looks like this:

Dim objOL as Object
Set objOL = CreateObject("Outlook.Application")

Rather than:

Set objOL = New Outlook.Application

You use the generic "object" designation when defining everything.  What it is then is not determined until runtime rather than design time.   In doing so, you don't tie yourself to a specific lib (version) of Outlook.   However, there are a few downsides:

1. About a 15% performance penalty

2. You don't get intellisense when developing.

3. You can't use pre-defined constants, such as olFolderContacts.

To get around some of that, many developers will do early binding during development, then switch to late binding for deployment.  You need to be careful when doing that however by always using the old version you plan to target for during development.

 For example, you would not want to set a reference to Outlook 2013, and possibly use a new feature from that, then deploy to someone who would have Outlook 2002.  Your code might break.   Your generally OK though going the other direction.

Jim.
0
 
LVL 2

Author Comment

by:hgj1357
ID: 40433799
"Set objOL = CreateObject("Outlook.Application")"

I get the same error. Can't create object.
0
 
LVL 2

Author Comment

by:hgj1357
ID: 40433916
Do I have the correct references?  I attached a few posts ago.
0
 
LVL 58
ID: 40434717
Then as Scott indicated in his first post, Outlook must not be installed locally at all.

When you late bind, a reference is not required.   It relies upon the registry to start up the last registered version of an application.  Since your getting an error when you go to do that, then Outlook is not installed.

Jim.
0
 
LVL 2

Author Comment

by:hgj1357
ID: 40434869
This is what I launch to start outlook  "C:\Program Files\Microsoft Office 15\root\office15\OUTLOOK.EXE"  it IS installed locally.
0
 
LVL 2

Author Comment

by:hgj1357
ID: 40434891
Do I have this entered correctly?

    Dim OlkApp As Object
    Dim olkCon As Object
   
   Set OlkApp = CreateObject("Outlook.Application")
   With OlkApp
      Set olkCon = .CreateItem(Outlook.OlItemType.olContactItem)
      With olkCon

.BusinessTelephoneNumber = strBusinessTelephonenumber
etc etc
.BusinessAddressPostalCode = strBusinessAddressPostalCode

         olkCon.Save
      End With
   End With
   
   ' Clean up.
   Set OlkApp = Nothing
   Set olkCon = Nothing
0
 
LVL 58
ID: 40434923
It is correct except for:

   Set olkCon = .CreateItem(Outlook.OlItemType.olContactItem)

You can't use any constants in the obj lib at design time because with late binding, references are not known/checked until run-time.  All the constant values can be found here:

http://msdn.microsoft.com/en-us/library/office/aa219371%28v=office.11%29.aspx

olContactItem has a value of 2, so:

   Set olkCon = .CreateItem(2)

Right now, you'll get a compile error.  

Make sure you've unchecked that outlook reference, do a compile, and make sure you have no errors.   If you still get a can't create active-x object, then something on the machine is messed up.

Jim.
0
 
LVL 2

Author Comment

by:hgj1357
ID: 40435008
OK.

The original code posted in the OP works 100%.

The problem was that I had:

MS Outlook 11.0 Object Library  when I actually needed:
MS Outlook 15.0 Object Library

Simple fix and it works like a charm.

Thanks
0
 
LVL 2

Author Comment

by:hgj1357
ID: 40435103
I've requested that this question be closed as follows:

Accepted answer: 0 points for hgj1357's comment #a40435008

for the following reason:

The problem was not he code but the reference.
0
 
LVL 58
ID: 40435104
0
 
LVL 58
ID: 40435107
Also note that by doing that, your code will now only work when Outlook 2013 is installed and no where else.

Your better off with late binding.

Jim.
0
 
LVL 2

Author Comment

by:hgj1357
ID: 40435125
I posted 5-6 references that I was using. You did state how to update my reference or what to update to. At least I didn't understand that's what you were getting at. I had no idea that "MS Outlook 11.0 Object Library" meant Outlook XP or that "MS Outlook 15.0 Object Library" exist.

The problem may be that I am too ignorant to understand some of what is posted here, that appears perfectly obvious to others.
0
 
LVL 58

Accepted Solution

by:
Jim Dettman (Microsoft MVP/ EE MVE) earned 2000 total points
ID: 40435162
Sorry, I missed the second part of your following comment, instead I focused on late binding, which is the way to go.

When you use a reference, you tie yourself to a very specific type lib.   Now that you've set that reference, while you code works (and I never said it was wrong), you app will no longer work with someone that has Outlook XP.

The only way to support both versions is:

1. Use late binding
2. Target your development for the oldest version.

 Which I mentioned in follow on comments.

Jim.
0
 
LVL 2

Author Comment

by:hgj1357
ID: 40435194
That's ok. I have an office of around 20. When we drop Outlook 2013 to go for something else, I will update everyone at the same time. The code runs slick as snot.
0
 
LVL 58
ID: 40435263
<<...slick as snot. >>

 and here I thought I was the only one that used that saying (I've gotten some odd looks)<g>.

Jim.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

715 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