Solved

Importing Outlook contacts into an Access database.

Posted on 2004-10-15
7
265 Views
Last Modified: 2008-03-06
Would like to create an Access database that automatically imports Outlook contact information from other user's email accounts.

An expert-exchanger was kind enough to provide me with the following code (which works perfectly), however, I am wondering if it can be modified to go the extra step of pulling not only my contacts but contact's from other email accounts to which I have rights.
I can accomplish this manually by simply going, 'File', 'Get External Data', 'Import' and then selecting 'Outlook' as a File Type but I sure would like to automate this.

Possible?????


Private Sub cmdGetContacts_Click()
  Dim myRecipient  As ContactItem
  Set myOlApp = CreateObject("Outlook.Application")
  Set myNamespace = myOlApp.GetNamespace("MAPI")
  Set myFolder = myNamespace.GetDefaultFolder(olFolderContacts)

  For iLoop = 1 To myFolder.Items.Count
    If TypeName(myFolder.Items(iLoop)) = "ContactItem" Then
      Set myRecipient = myFolder.Items(iLoop)
      sSQL = "INSERT INTO MasterContactList2 VALUES ('" & myRecipient.LastName & "','" & myRecipient.FirstName & "')"
      CurrentDb.Execute (sSQL)
    End If
  Next iLoop
  Set myOlApp = Nothing
  MsgBox "Completed Successfully", vbInformation, "Ok"
End Sub
0
Comment
Question by:mbath20110
  • 2
  • 2
7 Comments
 
LVL 15

Accepted Solution

by:
will_scarlet7 earned 250 total points
ID: 12320013
Changing the myFolder as below will allow you to pick the folder that you want to import from:

Private Sub cmdGetContacts_Click()
  Dim myRecipient  As ContactItem
  Set myOlApp = CreateObject("Outlook.Application")
  Set myNamespace = myOlApp.GetNamespace("MAPI")
  Set myFolder = myNamespace.PickFolder

  For iLoop = 1 To myFolder.Items.Count
    If TypeName(myFolder.Items(iLoop)) = "ContactItem" Then
      Set myRecipient = myFolder.Items(iLoop)
      sSQL = "INSERT INTO MasterContactList2 VALUES ('" & myRecipient.LastName & "','" & myRecipient.FirstName & "')"
      CurrentDb.Execute (sSQL)
    End If
  Next iLoop
  Set myOlApp = Nothing
  MsgBox "Completed Successfully", vbInformation, "Ok"
End Sub
0
 

Author Comment

by:mbath20110
ID: 12320517
Great!!

Figured it was something like that.  However, I'm struggling a bit with the syntax.

If I go the manual route, when I come to the dialog box that asks me to specify the particular user account, the user I want is listed as: 'Flores, Edmee'.

Soooo, how would that look?  

Set myFolder = myNamespace.Flores, Edmee?
Set myFolder = myNamespace.FloresEdmee?
Set myFolder = myNamespace.EdmeeFlores?

so far I'm getting a runtime:

Object doesn't support this method or property.
0
 
LVL 15

Expert Comment

by:will_scarlet7
ID: 12320804
Sorry I'm not real versed in Exchange environments... (I've never worked with it)
0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 250 total points
ID: 12506848
How about:

  Set myFolder = myNamespace.Items("Flores, Edmee")

or just:

  Set myFolder = myNamespace("Flores, Edmee")

/gustav
0
 

Author Comment

by:mbath20110
ID: 12507723
I'll give it a try ...   thanks!!!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

821 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