[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 887
  • Last Modified:

Extract Outlook Address book info from VB Application

i am now working on a faxmail client program. i would like to know the way to retrieve information from outlook address book without displaying the address book.( as i have already have the address book displayed by using the Mapimessages control action to show the address book).  I need to search the outlook address book for particular person's info and display it in the VB text boxes. How to do it?
0
riyugie
Asked:
riyugie
  • 2
1 Solution
 
watyCommented:
' #VBIDEUtils#************************************************************
' * Programmer Name  : Jan Amdi
' * Web Site         : www.geocities.com/ResearchTriangle/6311/
' * E-Mail           : jam@pfa.dk
' * Date             : 29/09/99
' * Time             : 14:34
' **********************************************************************
' * Comments         : Get the contacts from an Outlook Contact Database
' * If you have MS Outlook installed you might have organized all your contacts
' * in the Outlook address database. This tip shows you how to get all the contacts
' * in the address database from Visual Basic and put them in a ListBox.
' *
' * Before you begin you need to add a reference to the Outlook 8.0 object library.
' * Start a new project and add the reference from Project -> References and select
' * the 'Outlook 8.0 Object Library'. Add a ListBox to the form (List1).
' *
' * This tip doesn''t apply to MS Outlook Express (All versions).
' *
' **********************************************************************
Option Explicit

Sub GetContactList()

   On Error GoTo Test_Error

   Dim oOutlook As Outlook.Application
   Dim oNameSpace As NameSpace
   Dim oContactFolder As Object
   ' Get the currently opened Outlook session if any. If none is opened
   ' and error (Err = 429) is raised and the Error handler will open a
   ' new session of Outlook.
   Set oOutlook = GetObject(, "Outlook.Application")
   ' Open a MAPI NameSpace
   Set oNameSpace = oOutlook.GetNamespace("MAPI")

   Set oContactFolder = oNameSpace.GetDefaultFolder(olFolderContacts)

   For Each oOutLookAdr In oContactFolder.Item
      List1.AddItem oOutLookAdr.FullName & " - " & oOutLookAdr.Email1Address
   Next

   Exit Sub

Test_Error:

   Select Case Err
      Case 429
         ' If Outlook isn't opened already open a new session.
         ' It might be wise to close the session afterwards.
         Set oOutlook = New Outlook.Application
         Resume Next
      Case Else
         MsgBox Err
   End Select

End Sub
0
 
riyugieAuthor Commented:
what should i dim the oOutlookAdr as ?
As object ? or item? or what
0
 
riyugieAuthor Commented:
When i run the codes, there is an error saying that the oOutLookAdr variable is not defined... what should i do to proceed ??
0
 
ishmellCommented:
Just a followup for anyone reading this... the code above needs two things:

add this when dim'n vars

        dim oOutLookAdr as object

and change this line

        For Each oOutLookAdr In oContactFolder.Item

to this (forgot an "s" at the end):

        For Each oOutLookAdr In oContactFolder.Items



-a
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now