473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

VB & OutLook Address Book

I found this proven VB code on the internet, copy/pasted it but I get a "Method or data member not found" error on the line SET OLA=APPLICATION.SESSION... What am I doing wrong? Thanks -Ken.

Only needs "Microsoft Outlook xx.x Object Library - I used 11.0)
Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdAddress_Book_Click()
  2.    '---- create an listbox (I named it ab - Address Book)
  3.    Dim ola As Outlook.AddressList
  4.    Dim ole As Outlook.AddressEntry
  5.  
  6.    On Error Resume Next
  7.    Set ola = Application.Session.AddressLists("Contacts") 
  8.    For Each ole In ola.AddressEntries
  9.        ab.AddItem ole
  10.    Next
  11.    Set ola = Nothing
  12.    Set ole = Nothing
  13. End Sub
Apr 20 '08 #1
8 5843
ADezii
8,834 Expert 8TB
I found this proven VB code on the internet, copy/pasted it but I get a "Method or data member not found" error on the line SET OLA=APPLICATION.SESSION... What am I doing wrong? Thanks -Ken.

Only needs "Microsoft Outlook xx.x Object Library - I used 11.0)
Private Sub cmdAddress_Book_Click()
'---- create an listbox (I named it ab - Address Book)
Dim ola As Outlook.AddressList
Dim ole As Outlook.AddressEntry

On Error Resume Next
Set ola = Application.Session.AddressLists("Contacts")
For Each ole In ola.AddressEntries
ab.AddItem ole
Next
Set ola = Nothing
Set ole = Nothing
End Sub
I can't see how this code would ever work, since you have not fully qualified the Outlook Application Object. The code fails on this line because it expects to find a Method or Property of the Access Application Object, not Outlook, named Session. Of course this Property/Method does not exist. Once you indicate that you are explicitly referring to the Outlook Application Object (Lines 6 and 10), then then Session is a valid Property, and the code should now execute correctly. Be advised that I had no actual way of testing this Theory, I'm just assuming that it is correct.
Expand|Select|Wrap|Line Numbers
  1. '---- create an listbox (I named it ab - Address Book)
  2. Dim outApp As Outlook.Application
  3. Dim ola As Outlook.AddressList
  4. Dim ole As Outlook.AddressEntry
  5.  
  6. Set outApp = New Outlook.Application
  7.  
  8. On Error Resume Next
  9.  
  10. Set ola = outApp.Session.AddressLists("Contacts")
  11.  
  12. For Each ole In ola.AddressEntries
  13.   ab.AddItem ole
  14. Next
  15.  
  16. outApp.Close
  17.  
  18. Set outApp = Nothing
  19. Set ola = Nothing
  20. Set ole = Nothing
Apr 20 '08 #2
I can't see how this code would ever work, since you have not fully qualified the Outlook Application Object. The code fails on this line because it expects to find a Method or Property of the Access Application Object, not Outlook, named Session. Of course this Property/Method does not exist. Once you indicate that you are explicitly referring to the Outlook Application Object (Lines 6 and 10), then then Session is a valid Property, and the code should now execute correctly. Be advised that I had no actual way of testing this Theory, I'm just assuming that it is correct.
Expand|Select|Wrap|Line Numbers
  1. '---- create an listbox (I named it ab - Address Book)
  2. Dim outApp As Outlook.Application
  3. Dim ola As Outlook.AddressList
  4. Dim ole As Outlook.AddressEntry
  5.  
  6. Set outApp = New Outlook.Application
  7.  
  8. On Error Resume Next
  9.  
  10. Set ola = outApp.Session.AddressLists("Contacts")
  11.  
  12. For Each ole In ola.AddressEntries
  13.   ab.AddItem ole
  14. Next
  15.  
  16. outApp.Close
  17.  
  18. Set outApp = Nothing
  19. Set ola = Nothing
  20. Set ole = Nothing

Oh great one, You are correct. My next problem is that the for/next loop finds nothing to add. Is the actual name of MS OutLook Express address book called "Contacts"? I tried Contacts, MyContacts, and even some junk like DFGOIJEGUG and I keep getting the same result. Thanks -Ken.
Apr 21 '08 #3
ADezii
8,834 Expert 8TB
Oh great one, You are correct. My next problem is that the for/next loop finds nothing to add. Is the actual name of MS OutLook Express address book called "Contacts"? I tried Contacts, MyContacts, and even some junk like DFGOIJEGUG and I keep getting the same result. Thanks -Ken.
Again, I have no way to test this, but the following code should list all the entries in the Outlook Address Book, and Print them to the Immediate Window, I think (LOL).
Expand|Select|Wrap|Line Numbers
  1. Dim outApp As Outlook.Application
  2. Dim ola As Outlook.AddressList
  3. Dim intCounter As Integer
  4.  
  5. Set outApp = New Outlook.Application
  6.  
  7. On Error Resume Next
  8.  
  9. For intCounter = 1 To outApp.Session.AddressLists.Count
  10.   Debug.Print "Address List Entry #" & intCounter & ": " & _
  11.                outApp.Session.AddressLists(intCounter).Name
  12. Next
  13.  
  14. Set outApp = Nothing
  15. Set ola = Nothing
  16. Set ole = Nothing
Apr 21 '08 #4
Again, I have no way to test this, but the following code should list all the entries in the Outlook Address Book, and Print them to the Immediate Window, I think (LOL).
Expand|Select|Wrap|Line Numbers
  1. Dim outApp As Outlook.Application
  2. Dim ola As Outlook.AddressList
  3. Dim intCounter As Integer
  4.  
  5. Set outApp = New Outlook.Application
  6.  
  7. On Error Resume Next
  8.  
  9. For intCounter = 1 To outApp.Session.AddressLists.Count
  10.   Debug.Print "Address List Entry #" & intCounter & ": " & _
  11.                outApp.Session.AddressLists(intCounter).Name
  12. Next
  13.  
  14. Set outApp = Nothing
  15. Set ola = Nothing
  16. Set ole = Nothing

Oh great one, You are correct AGAIN. The address books name is "Global Address List" OutLook took noticed that I was looking at the address book because it put up a Window informing me that someone was trying to get to my address book and was that OK with me. "Contacts" never got a rise from OutLook!!! My same problem is still that the for/next loop finds nothing to add. Thanks -Ken.
Apr 21 '08 #5
ADezii
8,834 Expert 8TB
Oh great one, You are correct AGAIN. The address books name is "Global Address List" OutLook took noticed that I was looking at the address book because it put up a Window informing me that someone was trying to get to my address book and was that OK with me. "Contacts" never got a rise from OutLook!!! My same problem is still that the for/next loop finds nothing to add. Thanks -Ken.
BTW, thanks but absolutely no need for the great one reference. Try these 2 approaches to the problem, and see which, if either one, works:
Expand|Select|Wrap|Line Numbers
  1. '---- create an listbox (I named it ab - Address Book)
  2. Dim outApp As Outlook.Application
  3. Dim ola As Outlook.AddressList
  4. Dim ole As Outlook.AddressEntry
  5. Dim intNumOfEntries As Integer
  6.  
  7. Set outApp = New Outlook.Application
  8.  
  9. On Error Resume Next
  10.  
  11. Set ola = outApp.Session.AddressLists("Global Address List")
  12.  
  13. 'Try this method first
  14. For Each ole In ola.AddressEntries
  15.   Me![ab].AddItem ole.Name
  16. Next
  17.  
  18. 'Try this Method if the first does not work
  19. For intNumOfEntries = 1 To ola.AddressEntries.Count
  20.   Me![ab].AddItem ola.AddressEntries(intNumOfEntries).Name
  21. Next
  22.  
  23. Set outApp = Nothing
  24. Set ola = Nothing
  25. Set ole = Nothing
NOTE: I'm assuming you have either a List or Combo Box named ab on the Active Form and that you are using Access 2002 or greater in order to use the AddItem Method. Are these references True?
Apr 21 '08 #6
BTW, thanks but absolutely no need for the great one reference. Try these 2 approaches to the problem, and see which, if either one, works:
Expand|Select|Wrap|Line Numbers
  1. '---- create an listbox (I named it ab - Address Book)
  2. Dim outApp As Outlook.Application
  3. Dim ola As Outlook.AddressList
  4. Dim ole As Outlook.AddressEntry
  5. Dim intNumOfEntries As Integer
  6.  
  7. Set outApp = New Outlook.Application
  8.  
  9. On Error Resume Next
  10.  
  11. Set ola = outApp.Session.AddressLists("Global Address List")
  12.  
  13. 'Try this method first
  14. For Each ole In ola.AddressEntries
  15.   Me![ab].AddItem ole.Name
  16. Next
  17.  
  18. 'Try this Method if the first does not work
  19. For intNumOfEntries = 1 To ola.AddressEntries.Count
  20.   Me![ab].AddItem ola.AddressEntries(intNumOfEntries).Name
  21. Next
  22.  
  23. Set outApp = Nothing
  24. Set ola = Nothing
  25. Set ole = Nothing
NOTE: I'm assuming you have either a List or Combo Box named ab on the Active Form and that you are using Access 2002 or greater in order to use the AddItem Method. Are these references True?

I am using XP, Access 2003, and a List Box. When you helped me find the name of the OutLook Address Book, I only got one NAME back from that routine("Global Address List"). I was always wondering why I had not gotten more NAME's because I have several folders of e-mail addresses. "ola.AddressEntries.Count" = 0. Apparently I found an Address Book but its empty? Thanks -Ken.
Apr 21 '08 #7
I am using XP, Access 2003, and a List Box. When you helped me find the name of the OutLook Address Book, I only got one NAME back from that routine("Global Address List"). I was always wondering why I had not gotten more NAME's because I have several folders of e-mail addresses. "ola.AddressEntries.Count" = 0. Apparently I found an Address Book but its empty? Thanks -Ken.
Everytime I mention OutLook, I am talking about OutLook Express. Is this my problem all along? Ken
Apr 21 '08 #8
ADezii
8,834 Expert 8TB
Everytime I mention OutLook, I am talking about OutLook Express. Is this my problem all along? Ken
I honestly cannot say one way or the other, Ken.
Apr 22 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Iain Miller | last post by:
Currently using & developing a new application in A97. This app has a lot of Name & Address information in it. A lot of that information will be duplicated in Outlook & I suddenly wondered if its...
2
by: Phil Stanton | last post by:
Can anyone give me sone code to add addresses from a query to an Outlook Address book. The problem is that I want to add the new email addresses to a distribution list, not to the main email list ...
1
by: jmacione | last post by:
Problem Statement: Mary wants to share a distribution list of approximately 1000-2000 people with 3 other people. Sorfar I found three forms of address books that we can use for this. 1. ...
4
by: lauren quantrell | last post by:
Is there a way to open the MS Outlook address book using VBA and then be able to do something with the return value? I want users to click an icon to open the Outlook address book then when an...
0
by: Bob Avallone | last post by:
MetaPro Systems Inc. Visual Studio Dot Net Tips & Tricks #3 – Direct Access to Your Outlook Address Book. Project Type: VS.NET Windows Application Code Behind: Visual Basic I have a project...
2
by: hotelinfoline | last post by:
I want to get outlook express (not microsoft outlook express) address book address's in visual basic application. Please tell how I can get.
4
by: Alexander Szigetvary | last post by:
Hi NG! Is there a way to open the Outlook address book dialog (as in Outlook) using C#? I am using Outlook 2003 (MS Outlook 11.0 Object Library). In Outlook 2007 it can be done with...
1
by: Lpitt56 | last post by:
I am running MS Access 2007 and I want to update an Outlook Address book from my Access Database. I started out by importing the Outlook Address Book as a linked table and it linked fine. I then...
10
by: Mike Miller | last post by:
Hi, Am wanting to send email with php and need to access the global outlook address book. Are there any examples/tutorials on how to do this? M
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.